• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Constructors

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
Sonir
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sonir...
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){
this();
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
Ragu
[ January 20, 2002: Message edited by: Ragu Sivaraman ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic