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 Marcus exam Q30 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 "Marcus exam Q30" Watch "Marcus exam Q30" New topic
Author

Marcus exam Q30

rubna
Greenhorn

Joined: Jun 15, 2000
Posts: 25
Here is a question from Marcus
public class StrEq{
public static void main(String argv[]){
StrEq s = new StrEq();
}
private StrEq(){
String s = "Marcus";
String s2 = new String("Marcus");
if(s == s2){
System.out.println("we have a match");
}else{
System.out.println("Not equal");
}
}
}

The correct answer is "Not Equal".But according to RHE,the private constructor cannot be instantiated.Here,dont u think that it gives compiler error since the private constructor is instantiated?Please help me.
Thanks
rubna
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
A private constructor can be called from within its own class, as it is in this instance.
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
The reason I try to include entire classes in questions is so you can compile and try it yourself to see what happens. It is a great way to learn.
Marcus


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
rubna
Greenhorn

Joined: Jun 15, 2000
Posts: 25
Originally posted by Marcus Green:
The reason I try to include entire classes in questions is so you can compile and try it yourself to see what happens. It is a great way to learn.
Marcus

Thanks,
I tried compiling,but i did'nt get any error.That's why i was confused.I thought that it would give a compiler error telling
private constructors cannot be instantiated.
Thanks,i got it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Marcus exam Q30
 
Similar Threads
ambiguity in compilation error
simple question regarding strings
Why doesn't the subclass variable hide it?
Private constructor
string related question