| Author |
how do abstract classes like NumberFormat call the methods from their subclasses?
|
Prasad Kharkar
Ranch Hand
Joined: Mar 07, 2010
Posts: 438
|
|
according to Shaad's question about the private constructors, I had tried a small program that makes us access the object of a class that has all the constructors private
this is it
but even if the class constructors are private we could create the object of the class and could access it from outside the class
that also using the static method of the class like this
but in case of abstract classes those are in the java docs I mean classes like NumberFormat, DateFormat etc
we cannot instantiate them even in they are in the same class i.e. because they are abstract
then how can we use the instantiation method like above to get the object of the class?
like this
how is it done in the inbuilt classes ?
please help me
|
SCJP 6 [86%] June 30th, 2010
If you find any post useful, click the "plus one" sign on the right
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
Try out this program
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Prasad Kharkar
Ranch Hand
Joined: Mar 07, 2010
Posts: 438
|
|
does that mean that we are getting the instance of the class that extends the abstract class ?
and with the use of polymorphism?
means
DateFormat is referring to the subclass?
I will try to write a program for that definityly
|
 |
Prasad Kharkar
Ranch Hand
Joined: Mar 07, 2010
Posts: 438
|
|
I was checking for that
and found out something
like we instantiate DateFormat class as follows
as the DateFormat class is abstract and the object is of the subclass that extends the DateFormat class
I tried the program to check whether we can do it manually or not
when I run the program given by Ankit sir
that gives the name of the class is SimpleDateFormat
I tried that method with my code and got some similar results for my classes
here is it
this prints out
F:\Java\Javaranch problems>java ConcreteClass
Abstract class constructor
in the ConcreteClass constructor
Abstract class constructor
In the AnotherConcreteClass constructor with String argument
class ConcreteClass
class AnotherConcreteClass
My question here is
is this the way DateFormat and NumberFormat classes are created while creating java?
or is this the way that can resemble to that way?
Expecting help from Ankit sir and the great Henry sir
|
 |
Sandy Ghosh
Greenhorn
Joined: Jun 05, 2010
Posts: 26
|
|
Prasad Kharkar wrote:according to Shaad's question about the private constructors, I had tried a small program that makes us access the object of a class that has all the constructors private
this is it
but even if the class constructors are private we could create the object of the class and could access it from outside the class
that also using the static method of the class like this
but in case of abstract classes those are in the java docs I mean classes like NumberFormat, DateFormat etc
we cannot instantiate them even in they are in the same class i.e. because they are abstract
then how can we use the instantiation method like above to get the object of the class?
like this
how is it done in the inbuilt classes ?
please help me
At first when you calling this static method, The private constructor is getting invoked inside the class, so it is legal, and then it is returning the object to the caller..
the static method() is analogous to getInstance() method...
|
 |
 |
|
|
subject: how do abstract classes like NumberFormat call the methods from their subclasses?
|
|
|