Answers for "java inheritence"

2

Inheritance in java

// Multiple inheritance in java
interface M
{
   public void helloWorld();
}
interface N
{
   public void helloWorld();
}
// implementing interfaces
public class MultipleInheritanceExample implements M, N
{
   public void helloWorld()
   {
      System.out.println("helloWorld() method");
   }
   public static void main(String[] args) 
   {
      MultipleInheritanceExample obj = new MultipleInheritanceExample();
      obj.helloWorld();
   }
}
Posted by: Guest on November-23-2020
2

Inheritance in java

// Multilevel 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 Cub extends Lion
{
   void born()
   {
      System.out.println("cub drinking milk");
   }
   public static void main(String[] args)
   {
      Animal obj1 = new Animal();
      obj1.eating();
      Lion obj2 = new Lion();
      obj2.eating();
      obj2.roar();
      Cub obj3 = new Cub();
      obj3.eating();
      obj3.roar();
      obj3.born();
   }
}
Posted by: Guest on November-23-2020
2

Inheritance in java

// Hybrid inheritance in java
class A 
{
   public void display()
   {
      System.out.println("class A display method");
   }
}
interface B 
{
   public void print();
}
interface C
{
   public void print();
}
public class HybridInheritanceDemo extends A implements B, C
{
   public void print()
   {
      System.out.println("implementing print method");
   }
   public void show()
   {
      System.out.println("show method of class HybridInheritanceDemo");
   }
   public static void main(String[] args) 
   {
      HybridInheritanceDemo obj = new HybridInheritanceDemo();
      obj.show();
      obj.print();
   }
}
Posted by: Guest on November-23-2020
0

Inheritance in Java

Java Inheritance (Subclass and Superclass)
In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories:

subclass (child) - the class that inherits from another class
superclass (parent) - the class being inherited from
To inherit from a class, use the extends keyword.
Posted by: Guest on February-23-2021
0

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