create abstract method and override java code example
Example 1: override abstract method java
public interface Order
{
public boolean greaterThan(Order other);
}
public class AirCraft implements Order
{
private String make;
private int numSeats;
public AirCraft(String make, int numSeats)
{
this.make = make;
this.numSeats = numSeats;
}
public String getMake()
{
return make;
}
public int getNumSeats()
{
return numSeats;
}
@Override
public boolean greaterThan(Order other)
{
AirCraft x = (AirCraft)other;
return getNumSeats() > x.getNumSeats();
}
public String toString()
{
return make + " -> " + numSeats;
}
}
Example 2: write a program in which an abstract class is being defined containg an abstract method omputer(int a, int b) and a non abstract method as well
abstract class Sum{
public abstract int compute(int a, int b);
public void disp(){
System.out.println("Method of class Sum");
}
}
class Demo extends Sum{
public int compute(int a, int b){
return a+b;
}
public static void main(String args[]){
Sum obj = new Demo();
System.out.println(obj.compute(3, 7));
obj.disp();
}
}