Answers for "inheritance object creation in java"


Inheritance in java

// Hierarchical inheritance in java
class Animal
   void eating()
      System.out.println("animal eating");
class Lion extends Animal
   void roar()
      System.out.println("lion roaring");
public class Dog extends Animal
   void bark()
      System.out.println("dog barking");
   public static void main(String[] args)
      Animal obj1 = new Animal();
      Lion obj2 = new Lion();
      Dog obj3 = new Dog();
Posted by: Guest on November-23-2020

inheritance in java

it is used to define relationship between two class, 
which a child class occurs all the properties and
  behaviours of a parent class. 
Provides code reusability.
Ex: in my framework I have a TestBase 
class which I store 
all my reusable code and methods.
  My test execution classes and 
elements classes will extend the 
TestBase in order to reuse the code.
Posted by: Guest on November-28-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language