This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Default constructor !!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Default constructor !!!!" Watch "Default constructor !!!!" New topic
Author

Default constructor !!!!

Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 348
What will happen when you attempt to compile and run the following code
class Base{
public void Base(){
System.out.println("Base");
}
}
public class In extends Base{
public static void main(String argv[]){
In i=new In();
}
}
1) Compile time error Base is a keyword
2) Compilation and no output at runtime
3) Output of Base
4) Runtime error Base has no valid constructor

Here is the answer 2, but why not 3, i thought that In i=new In() will run the de default constuctor int the base class ???
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
you are correct BUT notice that the Base class didnt define a constructor at all!
the method is:
public VOID Base()
a constructor doesnt return anything.. not even void. so it isnt a constructor just a regular method.
Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 348
Off course Thanks a lot !
Frank , Hopefully SCJP2 the 26 of june !
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Default constructor !!!!
 
Similar Threads
Marcus Green's Tutorial
Question about Constructors on Marcus Green's Mock Exam #3
Marcus Green Mock exam Question # 16
method with name of constructor
constructor