what is java inheritance code example
Example 1: inheritance in java
class Animal
{
void eat()
{
System.out.println("Animal is eating.");
}
}
class Lion extends Animal
{
public static void main(String[] args)
{
Lion obj = new Lion();
obj.eat();
}
}
Example 2: inheritance in java codingsmania
class farmers
{
String crops="Wheat";
void grows();
{
System.out.println(“Farmers grows Wheat”);
}
}
public class Animals extends farmers
{
void eat();
{
System.out.println(“Animals eat Wheat”);
}
public static void main (String args[])
{
Animals obj=new Animals();
System.out.println(obj.crops);
obj.grows();
obj.eat();
}
}