ME-Q1) Given the following definition of the classes Animal, Lion, and Jumpable,
ID: 3718830 • Letter: M
Question
ME-Q1) Given the following definition of the classes Animal, Lion, and Jumpable, select the correct combinations of assignments of a variable that don't result in compilation errors or runtime exceptions (select 2 options). interface Jumpable ( class Animal class Lion extends Animal implements Jumpable [h 539 WOW! eBook www.wowebook.org CHAPTER 8 Full mock exam a Jumpable var1 = new Jumpable(); ? b Animal var2 = new Animal () ; [ ] c Lion var3 new Animal ( ) ; d Jumpable var4 e Jumpable var5 f Jumpable var6 new Animal () ; new Lion() ; (Jumpable) (new Animal ( )) ;Explanation / Answer
1. Jumpable var1 = new Jumpable();
error, interfaces cannot be instantiated.
2. Animal var2 = new Animal();
No error, proper code. Since, animal is a class and can be instantiated of that type only.
3. Lion var3 = new Animal();
Error, since a child class cannot refer to a parent class type.
4. Jumpable var4 = new Animal();
Error, since jumpable and animal are incompatible types.
5. Jumpable var5 = new Lion();
No error, since an interface can refer to an object that implements an interface, Lion being the case this time.
6. Jumpable var6 = (Jumpable) new Animal();
Answer:
Option 2
Option 5
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.