• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

casting...

 
Preethi Dev
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
//here
}
}

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

which code inserted here will not compile?
options:
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.

Thanks
Preetha
 
Preethi Dev
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops! sorry...options are wrongly typed
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an edit button to edit your post.
 
Jyothsna Panchagnula
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Preetha,

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

-Jyothsna
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic