00:00
I02_a.png
// I01 interface
/* 2. itf with m/t w/o abs keyword. */ interface I1 { void show(); } // compile successfully
/* 3. itf with m/t with abs kwyword.*/ interface I1 { abstract void show(); } // compile successfully
/* 4. itf with abs. m/t with public a/m. */ interface I1 { public abstract void show(); } // compile successfully
/* 7.itf with concrete m/t.*/ interface I1 { void show(); void display(){ System.out.println("hi"); } } // interface abstract methods cannot have body
/* 8. itf with concrete m/t ( default keyword. */ interface I1 { void show(); default void display(){ System.out.println("hi"); } } // compile successfully
/* 9. itf with concrete m/t ( static keyword. */ interface I1 { void show(); static void display(){ System.out.println("hi"); } } // compile successfully
/* 10. itf with variable */ interface I1 { int a = 10;// default = public static final void show(); } // compile successfully // deafutl public static final
/* 11. itf with var. having public static final keyword.*/ interface I1 { public static final int a = 10; void show(); } // compile successfully
/* 12. cls i/h itf m/t with weeker (default ) a/m. */ interface I1 { void show(); } class I12 implements I1{ void show(){// default System.out.println("class i/h i/t m/t"); } } // show() in I12 cannot implement show() in I1 // attempting to assign weaker access privileges; was public
/* 13. cls i/h itf m/t with public a/m. */ interface I1 { void show(); } class I13 implements I1{ public void show(){ System.out.println("class i/h i/t m/t with public keyword"); } } // compile successfully
/* 14. itf obj in main m/t , not acceptable. */ interface I1 { void show(); } class I14 implements I1{ public void show(){ System.out.println("interface object in main"); } public static void main(String[] args) { I1 i3 = new I1(); } }// I1 is abstract; cannot be instantiated
/* 15. make obj of cld. cls. and the use ts abs m/t */ interface I1 { void show(); } class I15 implements I1{ public void show(){ System.out.println("show m/t"); } public static void main(String[] args) { I15 i1 = new I15(); i1.show(); } }// compile successfully
/* 16. implment two itf and only create body of one itf. */ interface I1 { void show(); } interface I2{ void display(); } class I16 implements I1, I2{// only one itf body public void show(){ System.out.println("inherit m/t using public keyword"); } public static void main(String[] args) { I16 i1 = new I16(); i1.show(); } } // I16 is not abstract and does not override abstract method display() in I2
/* 15. implemnt two itf and create body of both itf. */ interface I1 { void show(); } interface I2{ void display(); } class I17 implements I1, I2{ public void show(){
System.out.println("show"); } public void display(){ System.out.println("display"); } public static void main(String[] args) { I17 i1 = new I17(); i1.show(); i1.display(); } } // show // display
Home PREVIOUS NEXT