Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Person{
- String name;
- int year;
- void getCommonDetails(){
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter the name: ");
- name = sc.next();
- System.out.print("Enter the year of birth: ");
- year = sc.nextInt();
- }
- }
- class Student extends Person{
- String major;
- Student(){
- System.out.println("A Student Object has been created.");
- }
- void getDetails(){
- getCommonDetails();
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter the subject the student is majoring in: ");
- major = sc.next();
- }
- void printDetails(){
- System.out.println(name+", born in "+year+" is majoring in "+major);
- }
- }
- class Instructor extends Person{
- int salary;
- Instructor(){
- System.out.println("An Instructor Object has been created.");
- }
- void getDetails(){
- getCommonDetails();
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter the salary of the instructor: ");
- salary = sc.nextInt();
- }
- void printDetails(){
- System.out.println(name+", born in "+year+" is earns Rs."+salary);
- }
- }
- class People{
- public static void main(String[] args){
- Student s = new Student();
- s.getDetails();
- Instructor i = new Instructor();
- i.getDetails();
- System.out.println("\n\n");
- s.printDetails();
- i.printDetails();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement