• 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

constructor

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Select all valid answers:
A1 The code will fail to compile.
A2 The constructor in A that takes an int as argument will never be called as a result of constructing an object of class B or Test11.
A3 class Test11 has three constructors.
A4 Atmost one of the constructors of each class is called as a result of constructing an object of class Test11.

The given answers are A2 and A3.I feel like A4 also a correct option.Please clarify.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shiva,

Please quote your sources.

Henry
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shiva Mohan:



Select all valid answers:
A1 The code will fail to compile.
A2 The constructor in A that takes an int as argument will never be called as a result of constructing an object of class B or Test11.
A3 class Test11 has three constructors.
A4 Atmost one of the constructors of each class is called as a result of constructing an object of class Test11.

The given answers are A2 and A3.I feel like A4 also a correct option.Please clarify.



If you create an instance of Test11 like this

,

then both the constructor of Test11 that accepts a String and the no-argument constructor of Test11 are called.
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply keith.

Any of the constructors of Test11 access atmost one of the constructor of each class since Test11 is a subclass of B,A.Right?
Then why the option A4 is not selected.

from your previous post,what are you saying? Maybe i am stupid to get that.Please help again.

Henry, i forgot.sorry.the question is from javabeat.
[ March 24, 2007: Message edited by: Shiva Mohan ]
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Option 4 says that at most one constructor of each class is called if you create an instance of Test11.

This is not true because if you create a Test11 object with the constructor that accepts a String, then that constructor immediately calls the no-argument constructor in Test11, which then calls the no-argument constructor of B, which calls the no-argument constructor of A, which calls the no-argument constructor of Object.
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't the A1 be valid too? I thought a constructor couldn't return a type... as B does. Maybe I was all this time wrong...
 
Joan Horta Tosas
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found the answer by myself doing tests... It will compile because method boolean B(String msg) is a method, not a constructor... I always thought that class names could just be used for constructors, not other methods, but maybe this thought was teached to me due to legibility.
Well, something new I've learned today!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
whenever we create the object reference based on integer constructor it will not call remaining constructor of other classes
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic