Answers for "inheritance java code"

2

Inheritance in java

// single inheritance example
import java.util.*;
class Animal
{
   void eat()
   {
      System.out.println("Animal is eating.");
   }
}
class Lion extends Animal
{
   void roar()
   {
      System.out.println("lion is roaring.");
   }
   public static void main(String[] args)
   {
      Lion obj = new Lion();
      obj.eat();
      obj.roar();
   }
}
Posted by: Guest on November-23-2020
0

inheritance in java

class Arithmetic {
    Arithmetic() {}
}

class Adder extends Arithmetic {
    Adder() {}
    
    int add(int a, int b) {
        return a + b;
    }
}
Posted by: Guest on August-10-2021
0

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();
  }
}
Posted by: Guest on January-21-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language