Siddhant Patil - D10A - 50 - Java Exp6
Siddhant Patil - D10A - 50 - Java Exp6
Theory :
1) To achieve security - hide certain details and only show the important details of an object
(interface).
2) Java does not support "multiple inheritance" (a class can only inherit from one super class).
However, it can be achieved with interfaces, because the class can implement multiple
interfaces.
When a class implements an interface, you can think of the class as signing a contract, agreeing
to perform the specific behaviors of the interface. If a class does not perform all the behaviors of
the interface, the class must declare itself as abstract.
A class uses the implements keyword to implement an interface. The implements keyword
appears in the class declaration following the extends portion of the declaration.
Example
System.out.println("Mammal eats");
System.out.println("Mammal travels");
return 0;
}
public static void main(String args[]) {
m.eat();
m.travel();
Output
Mammal eats
Mammal travels
Source code :
import java.util.Scanner;
interface Vehicle
void Display_Descriptions();
String company_name;
String colour;
int registration_NO;
String name_plate;
int no_of_wheel;
this.company_name=a;
this.colour=b;
this.registration_NO=c;
this.name_plate=d;
this.no_of_wheel=e;
System.out.println("registration number:"+this.registration_NO);
System.out.println("name:"+this.name_plate);
String company_name;
String colour;
int registration_NO;
String name_plate;
int no_of_wheel;
this.company_name=a;
this.colour=b;
this.registration_NO=c;
this.name_plate=d;
this.no_of_wheel=e;
System.out.println("colour :"+this.colour);
System.out.println("registration number:"+this.registration_NO);
System.out.println("name:"+this.name_plate);
String company_name;
String colour;
int registration_NO;
String name_plate;
int no_of_wheel;
this.company_name=a;
this.colour=b;
this.registration_NO=c;
this.name_plate=d;
this.no_of_wheel=e;
System.out.println("colour :"+this.colour);
System.out.println("registration number:"+this.registration_NO);
System.out.println("name:"+this.name_plate);
String a=sc.nextLine();
String b=sc.nextLine();
int c=sc.nextInt();
sc.nextLine();
String d=sc.nextLine();
int e=sc.nextInt();
obj.Set_Descriptions(a,b,c,d,e);
System.out.println("Description of car:");
obj.Display_Descriptions();
}
Output :