• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

creation of object using new operator

 
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
 
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)
 
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!