Answers for "inheritance in java types"

1

inheritance in java

Builds relations between classes, main purpose: 
create a TEST BASE CLAS and use it in other classes.
Inheritance allows a class to inherit properties 
(objects, variables, methods) from another source (class or interface). 
Allows code reusability and easy to maintain.
SUPER CLASS (also known as parent or base class): 
is the class where the fields are being inherited from. 
SUB CLASS (also known as the child or derived class): 
is the class inheriting the properties
INHERITANCE EXAMPLE
In my framework I have a TestBase class where 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. 
My framework follow POM and some pages have similar actions, 
so I can easily use those similar actions and fields 
by inheriting them from the ready classes.

  Example: Base Page Class and Test Base Class. 
These 2 class are being inherited from so many different classes. 
For Example; In Pages Package, Base Page Class is being extended 
by all the class by Base Package. So that Constructor 
can be automatically be called in the sub classes. 
That way you will be able to locate the elements 
by using same driver. 
Test Base Class can also be inheritance. 
One driver, TestNG framework one before method to 
setup browser and reuse it every single test class it. 
By inheriting them to other test class. These 2 class are 
abstract class and meant to be inherited to other classes. 
We are not creating any object in these 2 class. 
These class is super class. Comes from Selenium library WebDriver, 
takes Screenshots, javascriptexecuter these are interface. 
List and Set also interface. You cannot create object in interface. 
They are only being reference. These are also example for abstraction.
Posted by: Guest on June-17-2021
0

multilevel inheritance in java

class Car{
   public Car()
   {
	System.out.println("Class Car");
   }
   public void vehicleType()
   {
	System.out.println("Vehicle Type: Car");
   }
}
class Maruti extends Car{
   public Maruti()
   {
	System.out.println("Class Maruti");
   }
   public void brand()
   {
	System.out.println("Brand: Maruti");
   }
   public void speed()
   {
	System.out.println("Max: 90Kmph");
   }
}
class Maruti800 extends Maruti{

   public Maruti800()
   {
	System.out.println("Maruti Model: 800");
   }
   public void speed()
   {
	System.out.println("Max: 80Kmph");
   }
   public static void main(String args[])
   {
	 Maruti800 obj=new Maruti800();
	 obj.vehicleType();
	 obj.brand();
	 obj.speed();
   }
}
Posted by: Guest on September-08-2020
0

multilevel inheritance in java

class Car{
   public Car()
   {
	System.out.println("Class Car");
   }
   public void vehicleType()
   {
	System.out.println("Vehicle Type: Car");
   }
}
class Maruti extends Car{
   public Maruti()
   {
	System.out.println("Class Maruti");
   }
   public void brand()
   {
	System.out.println("Brand: Maruti");
   }
   public void speed()
   {
	System.out.println("Max: 90Kmph");
   }
}
public class Maruti800 extends Maruti{

   public Maruti800()
   {
	System.out.println("Maruti Model: 800");
   }
   public void speed()
   {
	System.out.println("Max: 80Kmph");
   }
   public static void main(String args[])
   {
	 Maruti800 obj=new Maruti800();
	 obj.vehicleType();
	 obj.brand();
	 obj.speed();
   }
}
Posted by: Guest on September-08-2020
0

inheritance in java

class Arithmetic {
    Arithmetic() {}
    
    int add(int a, int b) {
        return a + b;
    }
}

class Adder extends Arithmetic {
    Adder() {}
}
Posted by: Guest on August-10-2021

Code answers related to "inheritance in java types"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language