Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)

Given:

class One {
void foo() { }
}
class Two extends One {
14. // insert method here
}

Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)

Given:

class One {
void foo() { }
}
class Two extends One {
14. // insert method here
}

Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)

A.
int foo() { /* more code here */ }

B.
void foo() { /* more code here */ }

C.
public void foo() { /* more code here */ }

D.
private void foo() { /* more code here */ }

E.
protected void foo() { /* more code here */ }

Explanation:
A:
Main.java:14: foo() in Two cannot override foo() in One; attempting to use incompatible return type
found : int
required: void
int foo() { /* more code here */ }
^
1 error

B:
compiled successfully

C:
compiled successfully

D:
Main.java:14: foo() in Two cannot override foo() in One; attempting to assign weaker access privileges; was package
private void foo() { /* more code here */ }
^
1 error

E:
compiled successfully



Leave a Reply 0

Your email address will not be published. Required fields are marked *