Java Program to print student details using single inheritance

In this program, You will learn how to print student details using single inheritance in java.


class Student { 
   //statement
}

class College extends Student{ 
   //statement
}

Java Program to print student details using single inheritance

Example: How to print student details using single inheritance in java.

import java.io.*;

class Student {

    int roll;
    String cname;
    String uname;

    InputStreamReader in = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(in);

    void input() throws IOException {
        System.out.print("Enter Roll Number:");
        roll = Integer.parseInt(br.readLine());

        System.out.print("Enter College Name:");
        cname = br.readLine();

        System.out.print("Enter University Name:");
        uname = br.readLine();
    }
}

class Main extends Student {

    void display() {
        System.out.print("\nRoll Number is :" + roll);
        System.out.print("\nCollege Name is :" + cname);
        System.out.print("\nUniversity Name is :" + uname);
    }

    public static void main(String args[]) throws IOException {
        Main c = new Main();
        c.input();
        c.display();
    }
}

Output:

Enter Roll Number:101
Enter College Name:Xiith34
Enter University Name:Xiith.com

Roll Number is :101
College Name is :Xiith34
University Name is :Xiith.com