Given: 1. public interface A { 2. String DEFAULT_GREETING = “Hello World”; 3. public void method1(); 4. } A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?

  1. public interface B extends A { }

  2. public interface B implements A {}

  3. public interface B instanceOf A {}

  4. public interface B inheritsFrom A { }


Correct Option: A
Explanation:

To solve this question, the user needs to know the basics of Java interfaces and inheritance.

Option A is the correct answer: A programmer can create a child interface by using the "extends" keyword and specifying the parent interface name. In this case, interface B can be created by extending interface A as follows:

public interface B extends A {}

Option B is incorrect because the "implements" keyword is used to implement an interface, not to extend it.

Option C is incorrect because "instanceOf" is a keyword used to test if an object is an instance of a class, not to create an interface that inherits from another interface.

Option D is incorrect because "inheritsFrom" is not a valid keyword in Java to indicate inheritance.

Therefore, the answer is: A. public interface B extends A {}

Find more quizzes: