• 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 question

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(Question from "The Complete Java 2 Certification Guide" book)

public class Test extends Base{
public Test(int i){}

public Test(int j, int k) {
super(j,k)
}
}

What are the constructors must exist explicitly in the Base class?
a) Base(){}
b) Base(int j){}
c) Base(int j, int k){}
d) Base(int j, int k,int l){}

Answers (a) and (c).

Why we need option (a)? Please explain.

Thanks in advance.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one of your constructors doesn't call another constructor explicitly, therefore the no-argument constructor gets called on the superclass.
As you have a constructor with arguments in the superclass (as indicated by your other constructor which calls it), the no-argument constructor must be explicitly defined (for the simple reason that the implicit no-argument default constructor is supplied only when no constructors are defined at all).

Nice little tricky question, takes thinking to get the correct answer
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Indika S" please change your displayed name to conform to JavaRanch's Naming Policy.

In your case please use a first name (or initial) followed by a family name.

You may change your displayed name here.

Thankyou
 
Indika Hewage
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Jeroen
 
reply
    Bookmark Topic Watch Topic
  • New Topic