The process by which one class acquires the properties(data members) and functionalities(methods) of another class is called inheritance. The aim of inheritance is to provide the reusability of code so that a class has to write only the unique features and rest of the common properties and functionalities can be extended from the another class.

INHERITANCE

Aim:     

To perform the inheritance concept in the java programming language

Algorithm:

Step 1:   Create a new  text  document.

Step2:   Type the java program for implementing the inheritance concept.

Step3:   create a super class named “employee” and assign the float value  of salary,  
       assign the int value of bonus.                      
                      
Step4:   create a sub class named “programmer” , create the main method.

Step5:   create an object named “p” and print the variable  value of salary and bonus 
       using “System .out. println” command.

Step6:    Save the program with “.java” extension.

Step7:    In the command prompt, compile the program using “javac “ command.  If 
       the error occurs, slove it and run the program using “java" command.

Program:

class Employee

{

float salary=40000;

}

class Programmer extends Employee

{

int bonus=10000;

public static void main(String args[])

{

Programmer P=new Programmer();

System.out.println("Programmer Salary is:"+P.salary);

System.out.println("Programmer Bonus is:"+P.bonus);

}

}

OUTPUT:


BY
      REGU RAM SV.

1 Comments

Post a Comment

Previous Post Next Post