• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

instance of an abstract class

take Calendar

On the API page it is described as an abstract class, yet you
obtain it with it's static getInstance method.  Please explain.
Everywhere I turn instructors say you can not get an object
of an abstract class.  Does getInstance build something else?,
something which extends Calander?

Thanks
0
hank1
Asked:
hank1
  • 4
1 Solution
 
CEHJCommented:
You don't obtain it. You get a subclass that's assigned to a variable of type abstract
0
 
CEHJCommented:
>>Does getInstance build something else?,
something which extends Calander?

Yes
0
 
CEHJCommented:
Usually GregorianCalendar:

System.out.println(Calendar.getInstance().getClass());
0
 
hank1Author Commented:
So you can call static methods of abstract classes.
THis, and who know why, also works Cal.. c = new Cal...()

I didn't think you could do that either.

Thanks
0
 
CEHJCommented:
:-)

>> So you can call static methods of abstract classes.

yes

>>THis, and who know why, also works Cal.. c = new Cal...()

No it won't compile
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now