• 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

Marcus Green's exam 3 question

 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this here Marcus green Exam 3

Answer to Question 43)
Objective 6.2)
2) constructors cannot be overriden
Overloading constructors is a key technique to allow multiple ways of initialising classes. By definition constructors have noition constructors have no return values so option 3 makes no sense. Option 4 is the inverse of what happens as constructor code will execute starting from the oldest ancestor class downwards. You can test this by writing a class that inherits from a base class and getting the constructor to print out a message. When you create the child class you will see the order of constructor calling.


But I guess that first its the base class's constructor then the its superclass's and so on. Because first the base class's constructor is invoked which executes a call to super() (unless there is a call to this(), in which case the super call is deffered) which causes the superclass's constructor to be executed. Though, the constructor to finish the execution first is the superclass's constructor.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I think the explaination for the answer is correct. And u r also saying the same. First the derived class construtor is called, agreed. However it then calls the super, completes that and then comes to its own constructor.
check this out:
==========================
class TestInt{
TestInt()
{
System.out.println("in TestInt") ;
}
}
==========================
class Child extends TestInt
{
Child()
{
System.out.println("in Child") ;
}
public static void main(String args[])
{
Child myChild = new Child();

}
}
=========================================
The output is:
in TestInt
in Child
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Constructors have to always start from Object at the base of the hierarchy. The reason being that each constructor needs more memory and variable initialization added on to that used by the parent.
Bill
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seeing that I noticed my corrupt/redundant word in the answer (noition?). Just corrected it.
Marcus
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic