Q. What will be the output?
public interface InfA{
protected String getName();
}

public class Test implements InfA{
public String getName(){
return "test-name";
}
public static void main (String[] args){
Test t = new Test();
System.out.println(t.getName());
}
}

  • (A) test-name
  • (B) Compilation fails due to an error on lines 2
  • (C) Compilation fails due to an error on lines 1
  • (D) Compilation fails due to an error on lines 1 D. Compilation succeed but Runtime Exception
πŸ’¬ Discuss
βœ… Correct Answer: (B) Compilation fails due to an error on lines 2
Explanation: Illegal modifier for the interface method InfA.getName(); only public and abstracts are permitted.
Explanation by: Vinay
Illegal modifier for the interface method InfA.getName(); only public and abstracts are permitted.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
100
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Vinay
Publisher
πŸ“ˆ
89%
Success Rate