File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes John Hunt M.E Q51 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "John Hunt M.E Q51" Watch "John Hunt M.E Q51" New topic
Author

John Hunt M.E Q51

Vineet Sharma
Ranch Hand

Joined: Dec 30, 2000
Posts: 51
Please Explain:
class First{
public First (String s) {
System.out.println(s);
}
}
public class Second extends First {
public static void main(String args[] ) {

new Second();
}
}
A.Nothing happens
B.A string is printed to Standard Output
C.An exception is raised at runtime stating that there is no null parameter constructor in class First.
D.Runtime error is raised stating that the object has not been created.
E. class second will not compile as there is no null parameter constuctor in the class First.
Answer is E but I think it should be D. Because no object has been created.
Thanks
Pat Barrett
Ranch Hand

Joined: Jan 03, 2001
Posts: 63
Hello,
Actually, the line new Second(); is creating an object. Since Second is extending First, and since Second doesn't have an explicit default constructor, the lack of a default constructor in First will cause a compiler error.
Hope this helps,
Pat B.
Vineet Sharma
Ranch Hand

Joined: Dec 30, 2000
Posts: 51

Thanks Pat,
But is it not true that if we do not make a constructor,a default constructor is issued?
Regards
Vineet
Pat Barrett
Ranch Hand

Joined: Jan 03, 2001
Posts: 63
Yes, that is true... but since the "First" method has a constructor defined, you would need to create your own default, or zero arg constructor in "Second" if you wanted one used there.
Pat B.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: John Hunt M.E Q51