• Post Reply Bookmark Topic Watch Topic
  • New Topic

don't know why it is wrong?  RSS feed

 
R K Singh
Ranch Hand
Posts: 5390
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
again qie from Maha test
34. Assume that Sub1 and Sub2 are both subclasses of class Super.
Given the declarations:
Super super = new Super();
Sub1 sub1 = new Sub1();
Sub2 sub2 = new Sub2();
Which statement best describes the result of attempting to compile and execute the following statement:
super = sub1;
a) Compiles and definitely legal at runtime
b) Does not compile
c) Compiles and may be illegal at runtime
I think answer is b)
but evalution says WRONG.
answer page is not available ..
so ane1 plz...
CMIW
TIA
 
Arathi Rajashekar
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
super= sub;
Compiles fine. No casting is required. Because u are assigning sub to super. It is perfectly legal. But it may be legal at runtime. Si i will say answer is A
 
R K Singh
Ranch Hand
Posts: 5390
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arathi Rajashekar:
Hi,
super= sub;
Compiles fine. No casting is required. Because u are assigning sub to super. It is perfectly legal. But it may be legal at runtime. Si i will say answer is A

hi Rajashekar
here point is this that que is using KEYWORD as var, so compiler will raise error.
super = sub1; is also not correct .
You are right if super would have been any LEGAL identifier.
CMIW
 
R K Singh
Ranch Hand
Posts: 5390
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Val
is it Errata??
TIA
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, the answer would be a if the identifier was something else than the keyword super. The answer given by Maha is a, but I think that she didn't think about that identifier problem.
As the question is worded, the answer should be b,
and if you change the identifier "super" to any other legal identifier then the correct answer is a, i.e. the statement is legal.
HIH
 
R K Singh
Ranch Hand
Posts: 5390
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Val
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!