Given: 10. interface Data { public void load(); } 11. abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?

  1. . public class Employee extends Info implements Data { public void load() { /do something/ }

  2. public class Employee implements Info extends Data { public void load() { /do something/ }

  3. public class Employee extends Info implements Data { public void load() { /*do something */ }

  4. public class Employee implements Info extends Data { public void Data.load() { /*d something */ }


Correct Option: A
Explanation:

To solve this question, the user needs to understand the difference between an interface and an abstract class in Java. An interface is a contract that specifies a set of methods that a class must implement, while an abstract class can contain both abstract and non-abstract methods and serves as a base class for other classes to inherit from.

Option A is correct because it correctly uses the Data interface and Info class. The Employee class extends the abstract Info class and implements the Data interface, thus fulfilling the requirements of both. The load() method in Employee must be implemented because it is declared in both the Data interface and the Info abstract class.

Option B is incorrect because the order of the interface and extends keywords is wrong. It should be "implements Info extends Data", not "extends Data implements Info". Additionally, the load() method must be implemented because it is declared in both the Data interface and the Info abstract class.

Option C is correct because it correctly uses the Data interface and Info class. The Employee class extends the abstract Info class and implements the Data interface, thus fulfilling the requirements of both. The load() method in Employee must be implemented because it is declared in both the Data interface and the Info abstract class.

Option D is incorrect because it attempts to implement the load() method by prefixing it with the Data interface name, which is not valid syntax. The correct way to implement the load() method is to define it without any prefix, as in options A and C.

Therefore, the correct answer is:

The Answer is: A. public class Employee extends Info implements Data { public void load() { /do something/ }

Find more quizzes: