Super class variables not printing through sub class

Posted by Abhishek Singh on Stack Overflow See other posts from Stack Overflow or by Abhishek Singh
Published on 2012-07-04T15:06:44Z Indexed on 2012/07/04 15:15 UTC
Read the original article Hit count: 277

Filed under:
|

Can u tell me why this code is not displaying any result on the console.

class employee {
    protected String name;
    protected double salary;
    protected String dob;

    public employee(String name, double salary, String dob) {
        this.name = name;
        this.salary = salary;
        this.dob = dob;
    }

    public employee(String name, double salary) {
        this.name = name;
        this.salary = salary;
    }
}

public class Manage extends employee {
    String dept1;

    public Manage(String name, double salary, String dob, String dept1) {
        super(name, salary, dob);
        this.dept1 = dept1;
    }

    public Manage(String name, double salary, String dept1) {
        super(name, salary);
        this.dept1 = dept1;
    }

    public static void main(String args[]) {
        employee e = new employee("Vikas", 122345);
        employee e2 = new employee("Vikas", 122345, "12-2-1991");
        Manage m = (Manage) new Manage("Vikas", 122345, "Sales");
        Manage m2 = new Manage("Vikas", 122345, "12-2-1991", "sales");
        m.display();
        m2.display();
    }

    public void display() {
        System.out.println("Name " + name);
        System.out.println("Salary " + salary);
        System.out.println("Birth " + dob);
        System.out.println("Department " + dept1);
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about inheritance