Instnace from an abstract class
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sabu_vs
Posted On:   Friday, August 1, 2003 07:53 PM

Hi


I have the following doubt.

We can't create an object of an abstract class. But see below



Calendar c=Calendar.getInstance();

Canelendar is an abstract class and it's instance is created .

Could you please tell me why it is legal.

thanks

sabu

Re: Instnace from an abstract class

Posted By:   AlessandroA_Garbagnati  
Posted On:   Friday, August 1, 2003 11:10 PM

Hi,

Because you are getting an instance of a concrete class of that class. In your cod, the "c" contains a GregorianCalendar class.



Calendar c = Calendar.getInstance();

Calendar c = new GregorianCalendar();



The two lines of code above are exaclty the same. The first one is the right one to use, anyway.



Check out the Factory pattern.

About | Sitemap | Contact