-2
 1. 

interface A { 
 void display(); 
 } 
class B implements A { 
//not use here private,protected,default...... 
**public** void display(){
  System.out.println("i m interface method"); 
} 
public static void main(String args[]){
 A a1 = new B(); 
a1.display();
 }

}

i am totally confusion please help me....and sorry for my English. Thank u

2 Answers2

0

Interface states that your class should have some methods, you are not allowed to hide them (by making private), if you want to implement interface.

Method is public in Interface by a default, you are now allowed to reduce it visibility area=)

Vitaliy Moskalyuk
  • 2,463
  • 13
  • 15
0

The reason you must use public in your class, is because your method is implicitly public from the interface. The Java tutorial Defining an Interface says, in part,

All abstract, default, and static methods in an interface are implicitly public, so you can omit the public modifier.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249