• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how do abstract classes like NumberFormat call the methods from their subclasses?

 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try out this program
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 30
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Don't listen to Steve. Just read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic