File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Construcors" Watch "Construcors" New topic
Author

Construcors

Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 356
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){
super(i);
}
MyOver(String s, int i){
this(i);
//Here
}
}
1)MyOver m = new MyOver();
2)super();
3)this("Hello",10);
4)Base b = new Base(10);
The answer here is 4, but why not 1 also ???
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5287
    
  10

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Construcors