File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Construcors" Watch "Construcors" New topic


Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 358
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: 6529

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:
subject: Construcors
It's not a secret anymore!