Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

don't know why it is wrong?  RSS feed

 
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
 
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
 
Gold Digger
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!