Interface
package com.company;
interface Bicycle{
int a=45; //in interface we can give the properties in interfaces and that is final
void applyBrake(int decrement);
void speedUp(int increment);/*this interface will give the force to that class to implement all the method
if we implement the bicycle so we should implement applyBrake and speedUP
*/
}
interface HornBicycle{
void blowhornkk();
void blowhorndd();
}
class AvonCycle implements Bicycle,HornBicycle{//here we can use the two interfaces in same class where in abstract class cannot
int b=10;
void blowHorn(){
System.out.println("pee pee");
}
public void applyBrake(int decrement){
System.out.println("applying brake ");
}
public void speedUp(int increment){
System.out.println("applying speedUp");
}
public void blowhornkk(){
System.out.println("Kabhi khushi kabhi gumm pee pee ");
}
public void blowhorndd(){
System.out.println("Mai hoon naa po po ");
}
}
public class interfaces {
public static void main(String[] args) {
AvonCycle cycle=new AvonCycle();
cycle.applyBrake(1);
// System.out.println(cycle.a); --Correct
cycle.blowHorn();
cycle.blowhorndd();
cycle.blowhornkk();
cycle.speedUp(100);
// cycle.b=100;
// System.out.println(cycle.b);but here we can modify in the another class
// cycle.a=15; --X Error you cannot modify the properties interface as they are final
}
}
//o/p
45 pee pee Mai hoon naa po po Kabhi khushi kabhi gumm pee pee applying speedUp
Comments
Post a Comment