DUET PG Score Card 2021
NHAI Recruitment 2021
Bihar Board 12th Dummy Admit Card 2022
RBI Assistant Notification 2021
Jee Advanced 2021 Result
NIACL Assistant Recruitment 2021
SBI PO Online Form 2021

L36 Understanding Interface, Using Interfaces

// L36

Understanding Interface, Using Interfaces

B,D


package q11283;
public class InterfaceDemo {
public static void main(String[] args) {
Greeting g1 = new A();
Greeting g2 = new B();
System.out.println(g1.getGreetings("Thor"));
System.out.println(g2.getGreetings("Thor"));
}
}
interface Greeting {
String getGreetings(String name);
}
class A implements Greeting {
public String getGreetings(String name) {
return "Hi " + name;
}
}
class B implements Greeting {
public String getGreetings(String name) {
return "Hola " + name;
}
}

package q11284;

interface Car {

String getName();

int getMaxSpeed();

default void applyBreak() {

System.out.println("Applying break on " + getName());

}

static void getFastestCar(Car car1, Car car2) {

if (car1.getMaxSpeed() >= car2.getMaxSpeed()) {
  System.out.println("Fastest car is : " + car1.getName());

} else {
  System.out.println("Fastest car is : " + car2.getName());

}

}

}

class BMW implements Car {

String name;

int maxSpeed;

public BMW(String name, int maxSpeed) {

this.name = name;

this.maxSpeed = maxSpeed;

}

public String getName() {

return name;

}

public int getMaxSpeed() {
return maxSpeed;

}

}

class Audi implements Car {

String name;

int maxSpeed;

public Audi(String name, int maxSpeed) {

this.name = name;

this.maxSpeed = maxSpeed;

}

public String getName() {

return name;

}

public int getMaxSpeed() {
return maxSpeed;

}

}

public class MainApp {

public static void main(String args[]) {

int value = Integer.parseInt(args[1]);
int value1 = Integer.parseInt(args[3]);

BMW bmw = new BMW(args[0], value);

Audi audi = new Audi(args[2], value1);

Car.getFastestCar(bmw, audi);

}

}


Candidates having any kind of query so he/she can ask in our comment section. Our Panel will b reverting back as soon as possible. Thank You. For more details visit our website (https://speedjobalert.com/)

Leave a Comment