Look at this question
class A {
public int getCode(){ return 2;}
}
class AA extends A {
public void doStuff() {
}
public static void main(String[] args) {
A a = null;
AA aa = null;
a =(AA) aa;
a = new AA();
}
}
Given the following two declarations, which of the options will compile?
A a = null;
AA aa = null;
Answers:
a = (AA) aa; Correct - Agreed
a = new AA(); Correct - Agreed
((AA) a).doStuff(); Correct - Agreed
aa = (AA) a; Incorrect - Not agreed
This questiondoes not ask if the code inserted must run without errors, so the option 3 is compilable but not runnable. The option 4 is compilable and not runnable too, and still wrong. Can anyone clarify it to me please?
Thanks.
About Question enthuware.ocajp.i.v7.2.872 :
Moderators: Site Manager, fjwalraven
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.872 :
You are right option 4 should be marked correct. The comment on the option explains it correctly but it is wrongly marked as incorrect.
This will be fixed asap.
thank you for your feedback!
This will be fixed asap.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 37 guests