Sunday, August 12, 2012

Java program to read and print student information


import java.io.*;
class student
{
int slno;
String name;
student()
{
name=new String();
slno=0;
}
void get()throws IOException
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the name of the student: ");
name=br.readLine();
System.out.print("\nEnter the Serial Number: ");
slno=Integer.parseInt(br.readLine());
}
void disp()
{
System.out.println("Serial Number : "+slno+"\nName : "+name);
}
}
class studmark extends student
{
int m1,m2;
studmark()
{
m1=m2=0;
}
void get()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the mark1: ");
m1=Integer.parseInt(br.readLine());
System.out.println("Enter the mark2: ");
m2=Integer.parseInt(br.readLine());
}
void disp()
{
System.out.println("Mark1 = "+m1+"\nMark2 = "+m2);
}
}
class personal extends studmark
{
int w,age;
personal()
{
w=age=0;
}
void get()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Weight : ");
w=Integer.parseInt(br.readLine());
System.out.println("Enter the age : ");
age=Integer.parseInt(br.readLine());
}
void disp()
{
System.out.println("Weight = "+w+"\nAge = "+age);
}
}
class studinheritance
{
public static void main(String[] args)throws IOException
{
student x;
student y= new student();
x=y;
x.get();
x.disp();
studmark i;
x=i;
x.get();
x.disp();
personal p;
x=p;
x.get();
x.disp();
}
}

0 comments:

Post a Comment