Breaking

Search

Tuesday, June 23, 2020

inheritance program in java

Inheritance java Program using steps procedure

inheritance program in java


The java program to demonstrate the concept of inheritance program.inheritance program in java


procedure steps:

  • step 1:Define a class by Name College and Declare two instance
  •               Variable of type String.
  • step 2: Define a Parameter Constructor to get Set

  • step 3: Declare a Method display College () To Show the value given.
  • step 4: Define a Class Department which inrits.
  • step 5: Declare Two Instance Variable of type string and define a Constructor.
  • step 6: Using super keyword inside the Constructor Values to the Constructor of the Parent
  •               Super Class.
  • step 7: Define a Class By name College Demo.
  • step 8: Define a main().
  • step 9: Create object to "Department Class.
  • step 10: Using one object of sub classs we accese the Method in Super to Display.



For Example Inheritance Program:


Class College
{
String collegeName,prinicipalName;
College (String cName,String pName)
{
collegeName=cName;
principalName=pName;
}
void dispalyCollege()
{
System.out.println("College Name:"+collegeName);
System.out.println("Principal Name:"+ principalname);
}
}
class Department extends College
{
String deptName,holdName;
Department(String cName,StringpName,String dName,String hName)
{
super(cName,pName);
deptName=dName;
hodName=hName;
}
void displayDepartment()
{
System.out.println("Department Name:"+deptName);
System.out.println("Hod Name:"=hodName);
}
}
class CollegeDemo
{
public static void main(String args[])
{
Department d;
d=new Department("your college name","Your principal name",Department Name",hod name");
d.displayCollege();
d.displayDepartment();
}
}


For example:  Enter the d=new department("your college name",
"Your principal name",Department Name",hod name");

Output:

C:\in\java>javac CollegeDemo.java
C:\in\java>java CollegeDemo

College Name:
Principal Name:
Department Name:
Hod Name:

RESULT:
    Thus the program Succesfully Exected.

No comments:

Post a Comment