MCQ
Single Best Answer
Moderate
Q
[Inheritance]
Assume that class Check implements interfaces
A and B.
How many times will the method abc() be defined
in class Check?
interface A
{
final static int x = 5;
abstract void abc();
}
interface B
{
final static int y = 5;
abstract void abc();
}
Assume that class Check implements interfaces A and B. How many times will the method
abc() be defined
in class Check?
ID: #24950
Competency focused Practice Questions ISC Class XII Computer Science
5 views
Question Info
#24950Q ID
ModerateDifficulty
Competency focused Practice Questions ISC Class XII Computer ScienceTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer: Option B
Explanation
[Inheritance]
Assume that class Check implements interfaces A and B. How many times will the method
Assume that class Check implements interfaces A and B. How many times will the method
abc() be defined
in class Check?
interface A
{
final static int x = 5;
abstract void abc();
}
interface B
{
final static int y = 5;
abstract void abc();
}
Correct Answer: (b) Once
Understanding Interfaces:
Both interfaces A and B contain the same abstract method:
void abc();
When a class implements multiple interfaces containing identical method declarations, Java requires only one implementation of that method.
Example:
class Check implements A, B
{
public void abc()
{
System.out.println("Method implemented");
}
}
Why Only One Definition?
- Interface methods are abstract by default.
-
Both interfaces declare exactly the same method signature:
void abc();
- A single method implementation satisfies both interfaces.
Important Concept:
If multiple interfaces contain identical abstract methods,
only one implementation is needed in the implementing class.
Why Other Options are Incorrect?
| Option | Reason |
|---|---|
| Twice | Incorrect because identical methods from interfaces can be implemented using a single method. |
| Compile time error | No compile-time error occurs because method signatures are same. |
| Runtime error | No runtime error occurs if method is properly implemented. |
Conclusion:
The method abc() will be implemented only once in class
Check.
Correct Answer: (b) Once
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic