• 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

JavaCaps Mock Exams

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

AND HE GIVE ME THIS ANSWER ANY BODY EXPLAIN TO ME WHY
thnak you zaghal
 
zaghal mohd
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry the answer was :
Executing class A constructor followed by Executing class B constructor
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The super class constructor always runs to completion before the body of the subclass constructor is completed.
My mock exam has a lot of control flow questions related to constructors and each answer has a detailed explanation. Please see the Constructor exam on the topic exam page at the URL contained in my signature.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class B extends class A.
So when you create an instance of a B object, the class A constructor (with no parameters) is called first before calling the class B constructor. super() is implied.
Note: because class A has another constructor with parameters, if the default constructor had not been provided (ie. A(){...}), then the code wouldn't have compiled.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Poglitsch:
Class B extends class A.
So when you create an instance of a B object, the class A constructor (with no parameters) is called first before calling the class B constructor. super() is implied.
Note: because class A has another constructor with parameters, if the default constructor had not been provided (ie. A(){...}), then the code wouldn't have compiled.


The subclass constructor is actually called first, but the first line of the subclass constructor is an implicit or explicit call to the super class constructor. After the superclass constructor runs to completion then control returns to the subclass constructor.
 
zaghal mohd
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Every thing under my control now thank you for your explanations dan and david
Thanks for having some patience with me.
Yours respectfully zaghal
 
reply
    Bookmark Topic Watch Topic
  • New Topic