Review 1 (Year 3 Sem 2)

Review 1 is the first review in semester 2 of year 3, and the seventh review in the total of year 3. It is a review for inheritance and polymorphism, and is considered to be moderately easy.

Description
Review exercises help to prepare you for written assessments. You should attempt the review exercises after reviewing the topics, and you should NOT run any code to predict the output.

Unlocked after completion

 * Star Employee (Score at least 50% for Review Chapter 2)
 * I extends U (Score at least 80% for Review Chapter 2)

Question
Consider the following code: Select all the methods in ClassB which will result in a compile time error.

Options
◻ methodOne

◻ methodTwo

◻ methodThree

◻ methodFour

◻ methodFive

◻ methodSix

◻ methodSeven

◻ methodEight

Question
Which of the following sample code will not lead to any compilation error? Assume that all the classes are defined in separate files.

Options
◻

◻

◻

Question
Consider the following classes: Select the classes that can access variable x1.

Options
◻ ClassB

◻ ClassC

◻ ClassD

◻ ClassE

◻ None of the above

Question
Consider the following classes: Select the classes that can access variable x2.

Options
◻ ClassB

◻ ClassC

◻ ClassD

◻ ClassE

◻ None of the above

Question
Consider the following classes: Select the classes that can access variable x3.

Options
◻ ClassB

◻ ClassC

◻ ClassD

◻ ClassE

◻ None of the above

Question
Consider the following classes: Select the classes that can access variable x4.

Options
◻ ClassB

◻ ClassC

◻ ClassD

◻ ClassE

◻ None of the above

Question
Consider the following classes: State the output printed.

Question
Given the following definitions of classes AA and BB. What is the output of the program?

Question
Given the following definitions of classes AA and BB. What if (*) is changed to super?

Question
Which of the following statements about inheritance in Java is FALSE?

Options
◻ We can use the extends keyword to specify inheritance

◻ A class can extends from at most one other class

◻ A class declared as final cannot be inherited

◻ A method declared as final cannot be overridden

◻ A field declared as final cannot be accessed by the subclass

Question
Consider the following code: Which of the following statement is true?

Options
◻ The program will compile if the constructor in class X is removed.

◻ The program does not compile because TestX does not have a constructor TestX.

◻ The program compiles, but it has a runtime error due to the conflict on the method name print.

◻ The program runs fine.

◻ None of the above

Question
Consider the definition of classes A, B, and C below: Which of the following declaration and initialization of variable x would cause x.f(1) to print the string “A”? (i) A x = new B; (ii) A x = new C; (iii) B x = new B; (iv) C x = new C;

Options
◻ (ii) only

◻ (ii) and (iv) only

◻ (i) and (iii) only

◻ (i), (ii), and (iii) only

◻ (ii), (iii), and (iv) only

Question
Consider the following code: State what is the output printed

Question
Consider the following code: State what is the output printed

Question
Consider the following code: State what is the output printed