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 { }

class College extends Student{ }


Example: How to print student details using single inheritance in Java

Run it Now
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("\nEnter College Name :");
        cname = br.readLine();

        System.out.print("\nEnter 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 :Amarillo College
Enter University Name :Texas
Roll Number is :101
College Name is :Amarillo College
University Name is :Texas