• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mind Q question 34.

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody tell me whether the Mind Q Question 34 answer given is right or wrong ?!!!
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
My answer is b, but the answer is given as a. The reason for me to select b as answer is that the line
" Super super = new Super(); " uses the key word "super". If you change the object name "super" to anything else say "sup" it will work and the answer will be a.
Correct me if I'm wrong.


------------------
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I agree with you..
It must be just a mistake. super should have been sup or super1 or something ....
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your are right. However, it is always better to write sample code to test out such things. Not only you'll learn more but you'll also get a quick answer.
Just as an excercise:
String String = new String("String"); //Is this LOC valid?
What would you do? Would you go ask someone or just put this line in a test program and find the answer?
Do let me know the answer(for both)
-Paul.

------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus
 
Jayamani Suresh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anil,
There is no doubt about it.
This is the first thing I did before even posting it here.
I tested the code, as soon as I had the doubt to make myself clear.

Like you said, best thing to do is, write code and test it. But I just wanted to point out the error in the Mock Exam.
I hope the exam does not include such questions which leads to ambiguity.
Thanks,
 
Jayamani Suresh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to add.
The statement
String String = new String("String"); is valid !!!. I tested it !!!.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why does it work? I would think that it would kick out the var name String.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jayamani ,
I think this question has already been discussed in the earlier discussions and it is in the mock exam errata.when ever you get such doubts you can go and search out there coz i feel all the exams have been throughly discussed in the ranch .
Regards,
Shankar.
 
reply
    Bookmark Topic Watch Topic
  • New Topic