Skip to content

Instantly share code, notes, and snippets.

@hadifar
Created November 23, 2017 08:06
Show Gist options
  • Select an option

  • Save hadifar/a68c49084e7540b7b83840bb57092733 to your computer and use it in GitHub Desktop.

Select an option

Save hadifar/a68c49084e7540b7b83840bb57092733 to your computer and use it in GitHub Desktop.
interface vs abstract
//first interface
interface Example1{
public void display1();
}
//second interface
interface Example2 {
public void display2();
}
//This interface is extending both the above interfaces
interface Example3 extends Example1,Example2{
}
class Example4 implements Example3{
public void display1(){
System.out.println("display2 method");
}
public void display2(){
System.out.println("display3 method");
}
}
class Demo{
public static void main(String args[]){
Example4 obj=new Example4();
obj.display1();
}
}
Output:
display2 method
abstrac class می تواند توسط یک کلاس یا کلاس انتزاعی گسترش یابد یا به ارث برده شود
class Example1{
public void display1(){
System.out.println("display1 method");
}
}
abstract class Example2{
public void display2(){
System.out.println("display2 method");
}
}
abstract class Example3 extends Example2{
abstract void display3();
}
class Example4 extends Example3{
public void display2(){
System.out.println("Example4-display2 method");
}
public void display3(){
System.out.println("display3 method");
}
}
class Demo{
public static void main(String args[]){
Example4 obj=new Example4();
obj.display2();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment