INTERFACE IMPLEMENTS IN JAVA

INTERFACE, INHERITANCE, IMPLEMENTS


import java.util.Scanner;
interface Employee
{
 String name;
 int ecode;
 void accept();
}
class Manager implements Employee
{
Scanner sc=new Scanner(System.in);    
    int salary;
    public void accept()
    {
        System.out.print("\nENTER VALUES\nNAME: ");
        Employee.name=sc.next();    
        System.out.print("\nCODE: ");
        Employee.ecode=sc.nextInt();
        System.out.print("\nSALARY: ");
        salary=sc.nextInt();
    }
    public void show()
    {
        System.out.print("\n NAME: "+Employee.name);
        System.out.print("\n CODE: "+Employee.ecode);
        System.out.print("\n SALARY: "+salary);
    }
}
class Worker implements Employee
{
    Scanner sc=new Scanner(System.in);    
    int wages;
    public void accept()
    {
        System.out.print("\nENTER VALUES\nNAME: ");
        Employee.name=sc.next();    
        System.out.print("\nCODE: ");
        Employee.ecode=sc.nextInt();
        System.out.print("\nWAGES: ");
        wages=sc.nextInt();
    }
    public void show()
    {
        System.out.print("\n NAME: "+Employee.name);
        System.out.print("\n CODE: "+Employee.ecode);
        System.out.print("\n WAGES: "+wages);
    }
}
class MWIE
{
    public static void main(String[] args) {
        Manager m=new Manager();
        m.accept();
        Worker w=new Worker();
        w.accept();
        System.out.print("\n MANAGER DETAILS: \n"+m.show());
        System.out.print("\n WORKER DETAILS: \n"+w.show());
    }
}

Comments

Popular posts from this blog

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

PALINDROME NUMBER

FIBONACCI SERIES