• Post Reply Bookmark Topic Watch Topic
  • New Topic

creation of object using new operator  RSS feed

 
Dikesh Stha
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
suppose we have---
class A{}
class B extends C{}
class C extends D{}
class Test{
C c1=new C()//with this statement how many objects will be created???
}

with my knowledge internally 4 objects are created .without formation of objects of super classes sub class objects can not be created and cannot be able to access class variable..Is this right or not??

dikesh
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C c1=new C()
This would create a SINGLE object of class type C.
without formation of objects of super classes sub class objects can not be created and cannot be able to access class variable..Is this right or not??

Wrong.

You dont need a object of super class to access its members(non private)from subclass.( Think you should learn mmore about access modifiers)
 
Juva Yuva
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dikesh Stha:

without formation of objects of super classes sub class objects can not be created and cannot be able to access class variable..Is this right or not??

dikesh


Its possible to create an subclass object and use the variables and methods (state and behaviours ) of the super class without any reference to Super Class. If you dig in to the subject , you could realise how abstract classes and inheritance are used as super classes/interfaces without ever creating objects of them .

During inheritance , all the variables and methods ( including static , final) are inherited to the subclass except the constructors and private ones. And subclass behaves as if the inherited methods are their own methods and thats wat OOP is all about.

Juva
[ December 22, 2008: Message edited by: Juva Yuva ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!