• 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

Abstract Superclass

 
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While instantiating an object of a class that inherits from a abstract super class,implicitly super() from abstract class is also executed.Doesn't this mean that we actually "instantiate" abstract class?
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. When you create any instance of any class (maybe apart of Object), some super(something) is always called.
You don't instantiate abstract classes. It's just impossible.
 
Swapnil Dharane
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well... then how can we know of the events that take place when a super() in the mentioned scenario gets called?
we can be certain that super() belongs to abstract class which,in turn, will invoke its superclass (say Object) .
 
Rancher
Posts: 3742
16
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swapnil Dharane wrote:well... then how can we know of the events that take place when a super() in the mentioned scenario gets called?
we can be certain that super() belongs to abstract class which,in turn, will invoke its superclass (say Object) .


Constructors, despite their name, do not create objects. At the point the code in the constructor runs, the object already exists. The constructor (including calls to the super class constructors), are only for initialising the fields of an object.
 
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Joanne said, calling the constructor method does not create an object of a class... it is the new keyword that creates the object on the free store/heap and the constructor is used to initialize the created object to a desired state... So creating an object that inherits members from its abstract super-class does not create an instance of the abstract super-class, it creates an object of the class that extends it and the constructor is used to initialize the object's inherited members as well as its own members to a desired state.
 
Swapnil Dharane
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joanne and Rico. That helped a lot
 
reply
    Bookmark Topic Watch Topic
  • New Topic