Write a Java program to print student and faculty details using hirarchy inhiritance concept

Write a Java program to print student and faculty details using hirarchy inhiritance concept

Program
import java.util.*;
class A
{
    String name,location,address;
    char gender;
}

class Student extends A
{
    String id;
    float marks,fee;
    Student()
    {
        Scanner s=new Scanner(System.in);
        System.out.println("Enter name : ");
        name=s.next();
        System.out.println("Enter location : ");
        location=s.next();
        System.out.println("Enter address : ");
        address=s.next();
        System.out.println("Enter gender: ");
        gender=s.next().charAt(0);
        System.out.println("Enter id : ");
        id=s.next();
        System.out.println("Enter marks : ");
        marks=s.nextFloat();
        System.out.println("Enter fee : ");
        fee=s.nextFloat();
    }
    void studentDetails()
    {
        System.out.println("Name of the student is :"+name);
        System.out.println("location of the student is : "+location);
        System.out.println("Address of the student is : "+address);
        System.out.println("Gender of the student is : "+gender);
        System.out.println("Student id is : "+id);
        System.out.println("Marks of the student is : "+marks);
        System.out.println("Student Fee is : "+fee);
    }
}

class Faculty extends A
{
    float salary;
    String id;
    Faculty()
    {
        Scanner s=new Scanner(System.in);
        System.out.println("Enter name : ");
        name=s.next();
        System.out.println("Enter location :");
        location=s.next();
        System.out.println("Enter address : ");
        address=s.next();
        System.out.println("Enter gender :");
        gender=s.next().charAt(0);
        System.out.println("Enter id : ");
        id=s.next();
        System.out.println("Enter Salary : ");
        salary=s.nextFloat();
    }
    void facultyDetails()
    {
        System.out.println("Name of the Faculty is : "+name);
        System.out.println("location of the Faculty is : "+location);
        System.out.println("Address of the Faculty is:  "+address);
        System.out.println("Gender of the Faculty is : "+gender);
        System.out.println("Faculty id is : "+id);
        System.out.println("Faculty Salary is : "+salary);
    }
}
public class Main
    {
    public static void main(String args[])
    {
        Faculty F=new Faculty();
        F.facultyDetails();
    }
}

Output:

Enter name : sateesh
Enter location : Hyd
Enter address : kukatpally
Enter gender : M
Enter id : 1224
Enter marks : 98
Enter fee : 1000

Name of the student is : sateesh
location of the student is : Hyd
Address of the student is : kukatpally
Gender of the student is : M
Student id is : 1224
Marks of the student is : 98.0
Student Fee is : 1000.0

Enter name : Varshini
Enter location : Chennai
Enter address : Chennai
Enter gender : F
Enter id : 23
Enter Salary : 20000

Name of the Faculty is : Varshini
location of the Faculty is : Chennai
Address of the Faculty is : Chennai
Gender of the Faculty is : f
Faculty id is : 24
Faculty Salary is : 24000.0

Inheritance In Java



More Questions


134 . Write a Java program to print student details using multilevel inhiritance concept
135 . Write a Java program to print student and faculty details using hirarchy inhiritance concept
136 . Write a Java program with out using abstract keyword
137 . Write a Java program with using abstract keyword
138 . Abstract Practice Program 1
139 . Write a Java program to create object for abstract class
140 . Abstract Practice Program 2
141 . Abstract Practice Program 3
142 . Abstract Practice Program 4
143 . Abstract Practice Program 5
144 . Down Casting Program