my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JXAM Qs.... 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 "JXAM Qs...." Watch "JXAM Qs...." New topic

JXAM Qs....

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
This is a Q from JXam.
Consider the following piece of code and select the correct statements.

1. Object o = new String("abcd");
2. String s = o;
3. System.out.println(s);
4. System.out.println(o);
The following is displayed:

The code fails to compile at line 1.
The code fails to compile at line 2
The code fails to compile at line 4.
The code can be made to compile by changing line 1 to the following:
String o = new String("abcd");
The answer given is C. But I feel it should be C & E both.
Is it possible for the Inner Class to be the Sub class of the Outer Class ??
Paul A
Ranch Hand

Joined: Aug 25, 2000
Posts: 44
Yes. E should be correct too.
Yes. It is possible for the Inner Class to be the Sub class of the Outer Class. For. eg. the following code compiles fine...
class Outer
class Inner extends Outer

Get Certified, Guaranteed!

<A HREF="" TARGET=_blank rel="nofollow"></A> <BR>Get Certified, Guaranteed!
Ranch Hand

Joined: Aug 29, 2000
Posts: 41
Hello sonkal,
I have just tried out the program that you have written and found that C and E are correct. I dont understand why the answer is only C. Any one to further clarify on the same if this is wrong. What to do in these cases..
I agree. Here's the link:
subject: JXAM Qs....
It's not a secret anymore!