Which statement is true about the classes and interfaces?

Which statement is true about the classes and interfaces?

1. public interface A {
2. public void doSomething(String thing);
3. }

1. public class AImpl implements A {
2. public void doSomething(String msg) {}
3. }

1. public class B {
2. public A doit(){
3. //more code here
4. }
5. public String execute(){
6. //more code here
7. }
8. }

1. public class C extends B {
2. public AImpl doit(){
3. //more code here
4. }
5.
6. public Object execute() {
7. //more code here
8. }
9. }

Which statement is true about the classes and interfaces?

1. public interface A {
2. public void doSomething(String thing);
3. }

1. public class AImpl implements A {
2. public void doSomething(String msg) {}
3. }

1. public class B {
2. public A doit(){
3. //more code here
4. }
5. public String execute(){
6. //more code here
7. }
8. }

1. public class C extends B {
2. public AImpl doit(){
3. //more code here
4. }
5.
6. public Object execute() {
7. //more code here
8. }
9. }

A.
Compilation will succeed for all classes and interfaces.

B.
Compilation of class C will fail because of an error in line 2.

C.
Compilation of class C will fail because of an error in line 6.

D.
Compilation of class AImpl will fail because of an error in line 2.

Explanation:
C.java:6: execute() in C cannot override execute() in B; attempting to use incompatible return type
found : java.lang.Object
required: java.lang.String
public Object execute() {

There is a compilation error in class C (Line 6) since execute() method is not correctly overriding Class B execute() method.



Leave a Reply 0

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