Friday 12 November 2021

single_inheritance

oops

Object Orinted programming

4 Inheritance

Inheritance is the producer by which one object acquries all the proprties and behavior of a parent object.It is Inheritance the properties of parent class into chlid class.

It is always better pre existing rather than creating all over agian .this is done using Inheritance. inheritance provide us alway using which we can use pre-existing our current programming/application.

it is with inheritance one class derive the properties of another class.

java:- By using extends Keyword to achive inheritance

Advantage of Inheritance

  • Inheritance promotes reusability. When a class inherits or derives another class, it can access all the functionality of inherited class.
  • Reusability enhanced reliability. The base class code will be already tested and debugged.
  • Inheritance makes the sub classes follow a standard interface.
  • Inheritance helps to reduce code redundancy and supports code extensibility.
  • Inheritance facilitates creation of class libraries.

DisAdvantage of Inheritance

  • Inherited functions work slower than normal function as there is indirection.
  • Improper use of inheritance may lead to wrong solutions.
  • Often, data members in the base class are left unused which may lead to memory wastage.
  • Inheritance increases the coupling between base class and derived class. A change in base class will affect all the child classes.

Object

Type of Inheritance:--------- 5

1. Single Inheritance

When one base class is being to derived class (Single) is called as Single inheritance.

Object

how to calcaulate area of reactangle by using single Inheritance ?

Single Inheritance

  • import java.util.Scanner;
  • public Class a
  • {
  • public
  • int lenght,breath ;
  • public void get()
    {
  • Scanner sc = new Scanner(System.in);
  • System.out.println( " enter the lenght ");
  • lenght=sc.nextInt();
  • System.out.println( " enter the breath ");
  • breath=sc.nextInt();
  • }
  • Class b extends a
  • {
  • void display()
  • {
  • System.out.println( " Area of reactangle = "+lenght+breath);
  • }
  • }
  • Class simple
  • {
  • public static void main (String args[])
    {
  • b aa = new b () ; ................//create the object of class
  • aa.get() ; ................//call the method
  • aa.display() ; ................//call the method
  • }
  • }
  • }
  • class Animal :
  • def make_eat(self):
  • print("i am eatting"")
  • a1=Animal
  • a1.eat()+
  • CONTENT FIR TAB 4

    Input

    enter the lenght =10

    enter the breath =10

    output

    Area of reactangle = 100.

    No comments:

    Post a Comment

    How do you select data from a table in SQL?

    Create Table How do you select data a table in SQL? The SELECT statement is used to se...