override methods in abstract class 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: abstract class example in java
//abstract parent class
abstract class Animal{
//abstract method
public abstract void sound();
}
//Dog class extends Animal class
public class Dog extends Animal{
public void sound(){
System.out.println("Woof");
}
public static void main(String args[]){
Animal obj = new Dog();
obj.sound();
}
}