Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes casting... 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 "casting..." Watch "casting..." New topic


Preethi Dev
Ranch Hand

Joined: Sep 07, 2008
Posts: 265
Hi,this from Master exam.

class putter
public static void main(String args[])
Bango b1=new Bango();
Bango b2=new Bongo();
Bango b3=new Bingo();

class Bango{}
class Bongo extends Bango{}
class Bingo extends Bongo{}

which code inserted here will not compile?
A.Bongo b5=(Bongo)b2;
B.Bango b6=b3;
C.Bango b7=(Bango)b3;
D.Bingo b9=(Bingo)b3;
E.Bango b10=(Bongo)b3;

Answer given is A and E.
but when i tried all it compiles and runs without error ad exception.
please give me the correct answer.

Preethi Dev
Ranch Hand

Joined: Sep 07, 2008
Posts: 265
oops! sorry...options are wrongly typed
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15080

There is an edit button to edit your post.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Jyothsna Panchagnula
Ranch Hand

Joined: Jul 11, 2005
Posts: 113
Hello Preetha,

Even I too ran the program. I dont see any compilation errors.

I agree. Here's the link:
subject: casting...
It's not a secret anymore!