inheritance

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.

4.33
6
Anthony 125 points

                                    class Employee():   def __init__(self, emp_id, salary):      self.emp_id = emp_id      self.salary = salary  def give_raise(self):      self.salary = self.salary * 1.05

4.33 (6 Votes)
0
3.8
5
Felix G 95 points

                                    #include <iostream>

using namespace std;

class Area
{
	public:
		int getArea(int l, int b)
		{
			return l * b;
		}
};

class Perimeter
{
	public:
		int getPerimeter(int l, int b)
		{
			return 2*(l + b);
		}
};

class Rectangle : public Area, public Perimeter
{
	int length;
	int breadth;
	public:
		Rectangle()
		{
			length = 7;
			breadth = 4;
		}
		int area()
		{
			return Area::getArea(length, breadth);
		}
		int perimeter()
		{
			return Perimeter::getPerimeter(length, breadth);
		}
};

int main()
{
	Rectangle rt;
	cout << "Area : " << rt.area() << endl;
	cout << "Perimeter : " << rt.perimeter() << endl;
	return 0;
}

3.8 (5 Votes)
0
0
7
Lucien 85 points

                                    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.

0
0
3.86
7

                                    // 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();
   }
}

3.86 (7 Votes)
0
4.17
6
R3D 105 points

                                    class Vehicle
{ 
  public Vehicle()
  { 
    System.out.print("Default "); 
  } 
} 
class Car extends Vehicle
{ 
public Car(String carName)
{ 
System.out.print(carName + ""); 
} 
} 
public class InheritanceTester
{
  public static void main(String[] args) 
  { 
    Car car=new Car("Ford");
  }
}

4.17 (6 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
java inheritance program example what is Inheritance java class inheritence java inheritance ? : inheritance how inheritance works wat is inheritance what is the meaning of inheritance function inheritance in java inheritance in java definition what is an inheritance java class inheritance programs examples inheritance of inheritance inheritance mean explain inheritance Java Inheritance II example of inheritance in java inheritance \meaning inheritance methods java inheritance syntax inheritance inheritance examples of inheritance class in java definition of inheritance in java Inheritance. inheritance with java inheritance explained inheritance example Inheritance t inheritance in java example inheritance in java with example example of java class inheritance can i both inherit and implement in java what does inheritance mean which keyword is used for inheritance in java inheritence in java inheriting in java java class inheritance inheritance example in java inheritance java definition how is interface inheritance in java the inheritance implementing inheritance in java meaning of inheritance how does inheritance work java inherit class in java how do you do inheritance in java inheritance "is a" inheritance in java how inheritance in java What is inheritance ? Inheritance is a... java inheritance example what is the inheritance class inheritance in java Why use inheritance in java? * java inheritance inheritance meaning in java Inheritance examples inherits java definition of inheritance java inherit What is meant by inheritance in Java Define inheritance. inheritence java what is the keyword used for inheritance in java why use inheritance in java what does inheritance do definition inheritance inheritance definition define inheritance what inheritance what is inheritance inheritance basic java how java inheritance works purpose of inheritance inheritance object oriented programming inheritance jelentése how does inheritance work what is inheritance definition inheritance meaning simple java inheritance program inheritance oop how do you inherit in java simple java program with inheritance program to show inheritance in java inherit class java the inheritance movie java basic syntax of in heritance inheritance explain inheritane in java heritance example java inheritance in java errors meaning single inheritance JAVA inheritance (2020) iheritance in java inheritance syntax java inheritance example java composition and inheritance java inheritance program inheritance 2020 which keyword used for deriving classes in java. inheritance in java \ Inheritance java extends example inheritance java java inheritence java inheri what is inheritance in java java inherits hierarchical inheritance program in java java inheritance code heritance java examples of java inheritance types of inheritance in java Inheritance in java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source