Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown


Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which statements concerning the following code are true?

Options :
1)One of the constructors of each class as a result of consulting an object of class C
2)Constructor //A2 will never be called in a creation of an object of Class C
3)Class C can be instantiated only in two ways by users of this class
4)//B1 will never be called in creation of Objects if Class A B or C
5)The code will not compile
Answer : 1) 2) 3) 4)
Can anyone explain me the above answers step wise what is it trying to say?
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you trace up the constructors you will see at least one of the constructor in each class gets called. Class B may be baffling, but it still gets called becoz, super() actually calls a dummy constructor since class B doesnt have any constructor at all..
2. Class B calls the empty constructor from the class A (implicitily ) . So A2 is never touched..
3.private C(){ super(); } // C1
public C(String s){
System.out.println("C :"+s); } // C2
public C(int i){} // C3
Very obvious , Class c can only be constructed by 2 forms. private C() cant be used...
4. B1 is never called ? why? it not even a constructor!!
Enjoy Sonir
[ January 20, 2002: Message edited by: Ragu Sivaraman ]
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic