This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes scjp5.0 question from 2nd chapter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "scjp5.0 question from 2nd chapter" Watch "scjp5.0 question from 2nd chapter" New topic
Author

scjp5.0 question from 2nd chapter

nikunj thakur
Ranch Hand

Joined: Sep 23, 2007
Posts: 47
class Dog { }
2. class Beagle extends Dog { }
3.
4. class Kennel {
5. public static void main(String [] arfs) {
6. Beagle bl = new Beagle();
7. Dog dogl = new Dog();
8. Dog dog2 = bl;
9. // insert code here
10. } }

Which, inserted at line 9, will compile? (Choose all that apply.)

Beagle b2 = (Beagle) dog1;

Beagle b3 = (Beagle) dog2;

Beagle b4 = dog2;

None of the above statements will compile.


The answer is 1st & 2nd line,but when i run the program it showing error
for the 1st answer
Praveen Seluka
Ranch Hand

Joined: Jul 17, 2007
Posts: 95
Hi

KB says the first two line would compile but the firstline would give a runtime exception.Check it out.
P Ventura
Ranch Hand

Joined: Jan 24, 2007
Posts: 42
First line compile because all assignment and casts are correct, but throw a runtime exception: the actual object is not a Beagle.

Second line compile and run correctly.


Objective: SCJP 1.5<br /><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html" target="_blank" rel="nofollow">API</a><br /> <blockquote><font size="1" face="Verdana, Arial">code:</font><hr><pre><font size="2"><br />Double n1 = Double.NaN; Double n2 = Double.NaN;<br /> n1.equals(n2) // true even though Double.NaN != Double.NaN<br />-0.0 == +0.0; // true<br />Double n1 = -0.0;Double n2 = +0.0;<br />n1.equals(n2) // false even though -0.0 == +0.0<br /></font></pre><hr></blockquote>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: scjp5.0 question from 2nd chapter