Inheritance 1
Inheritance 1
No: 2 Date:23/6/11
INHERITANCE
Objective: To provide strong knowledge in Inheritance. Problem Statement: Calculate the student mark list using inheritance. Concept: Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality. Syntax: Class <BaseClass> { Variables Methods. } Class <DerivedClass> extends <BaseClass> { Variables Methods. } Example: class A { void show() { System.out.prinltn(I Am A); } } Class B extends A { void show1() { System.out.prinltn(I Am B); } }
Running Procedure: Step 1: Enter The Dos Operating System Start - > Run -> Cmd Step 2: Create the Directory c:\> cd \ c:\> md java c:\> cd java c:\java> Step 3: Set the path c:\java> set path=%path%; C:\Program Files\Java\jdk1.5.0_01\bin; Step 4: Open the editer c:\java>edit Step 5: Type the program and save as Inheritance.java file extension Step 6: Compile the program c:\java>javac Inheritance.java Step 7: Run the program c:\java>java Inheritance Program Creating Procedure: 1. Create the class as Student. In the Student class declare rno variables as int data type. Declare the get_number and put_number method. 2. Create the class as Test and extends the Student class. declare sub1,sub2,sub3 variables as int data type. Declare the get_mark and put_mark method. 3. Create the class as Result and extends the Test class. declare tot variables as flaot data type. Declare the display method. 4. Create the class as Inheritance. In the main method create the Result class object using new keyword. Call the corresponding methods.
Result: Thus the program to implement inheritance has been compiled and executed successfully.