- IA-S relationship is also represent java interface.
- it can not be instance just like abstraction class.
- it is used achive abstraction
- functionality of multiple inheritance are supported by interface.
- loose coupling is achieve by interface.
interface area
{
public float compute(float x);
}
class circle implements area{
public float compute(float x)
{
float pi=3.142f;
return(pi*x*x);
}
}
class inter1
{
public static void main(String[] args) { circle c1= new circle();
area a1;
a1=c1;
System.out.println("Area of circle is "+a1.compute(3.0f));
}
}
Output:-
Code:
import java.util.Scanner;
interface student
{
String nm="kiran";
public void get();
public void display();
}
abstract class result implements student
{
float avg;
int rno,m1,m2;
public void get()
{
Scanner s=new Scanner(System.in);
System.out.print("Enter Roll No.:");
rno=s.nextInt();
System.out.print("Enter Marks1:");
m1=s.nextInt();
System.out.print("Enter Marks2:");
m2=s.nextInt();
}
}
class grade extends result
{
public void display()
{
avg=(m1+m2)/2f;
System.out.println("Name:"+nm+"\nRoll
No.:"+rno+"\nM1:"+m1+"\nM2:"+m2);
System.out.println("Avg:"+avg);
}
}
class inter3multi
{
public static void main(String[] args) { grade r=new grade();
r.get();
r.display();
}
}
Output:-
0 Comments