Sunday, 4 August 2013

Inheritance using Java

Student.java

import java.util.Scanner;
class std
{
String name;
String roll;
}
class stdData extends std
{
String Dept;
String Class;
String clg;
}
class Details extends stdData
{
Scanner in=new Scanner(System.in);

void addStd(){
System.out.print("\nEnter Name:");
name=in.nextLine();
System.out.print("Enter Roll:");
roll=in.nextLine();
System.out.print("Enter Department:");
Dept=in.nextLine();
System.out.print("Enter Class:");
Class=in.nextLine();
System.out.print("Enter College:");
clg=in.nextLine();

}
void viewStd(){
System.out.println("\nName:"+name+"\nRoll:"+roll+"\nDepartment:"+Dept+"\nClass:"+Class+"\nCollege:"+clg);
}
}
class Student
{
public static void main(String args[]){
Details dtl=new Details();
dtl.addStd();
dtl.viewStd();
}

}

Output:
Enter Name:Asif
Enter Roll:21364
Enter Department:CST
Enter Class:3rd Year
Enter College:DP

Name:Asif
Roll:21364
Department:CST
Class:3rd Year
College:DP

Thanks for watching ...comment it.

No comments:

Post a Comment