permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Construcors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Construcors" Watch "Construcors" New topic


Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 348
Given the following class definition which of the following can be legally placed after the comment line
//Here ?
class Base{
public Base(int i){}
public class MyOver extends Base{
public static void main(String arg[]){
MyOver m = new MyOver(10);
MyOver(int i){
MyOver(String s, int i){
1)MyOver m = new MyOver();
4)Base b = new Base(10);
The answer here is 4, but why not 1 also ???
Junilu Lacar

Joined: Feb 26, 2001
Posts: 4442

The compiler will provide a default (no-args) constructor only if there are no other constructors explicitly declared. Since class MyOver has two explicitly declared constructors that take arguments, the compiler does not provide a default constructor, making 1 an incorrect choice.
subject: Construcors
Similar Threads
Competition between “this”and “super” in constructor
marcus Green question
is it righ?
MarcusMock No - 2 - Question 53.
Mock of Marcus Green