inheritance in java
class Arithmetic {
}
class Adder extends Arithmetic {
public int add(int a, int b)
{
return a+b;
}
}
inheritance in java
class Arithmetic {
}
class Adder extends Arithmetic {
public int add(int a, int b)
{
return a+b;
}
}
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();
}
}
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();
}
}
inheritance in java
Inheritance in Java is a mechanism in which one object acquires
all the properties and behaviors of a parent object.
It is an important part of OOPs (Object Oriented programming system).
inheritance in java
class Arithmetic {
Arithmetic() {}
}
class Adder extends Arithmetic {
Adder() {}
int add(int a, int b) {
return a + b;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us