concept class programmer in category java

appears as: class Programmer
OCA Java SE 8 Programmer I Certification Guide

This is an excerpt from Manning's book OCA Java SE 8 Programmer I Certification Guide.

The base class Employee defines two non-private variables, name and address, which are accessible in Employee’s derived class Programmer. The class Programmer also defines an instance variable name, so the variable name should be prefixed with the explicit references super and this to refer to the variable name defined in the classes Employee and Programmer. The variable address can be referred to using both super and this in the derived class Programmer.

class Employee {
    private String name;
    String address;
    protected String phoneNumber;
    public float experience;
}
class Programmer extends Employee {
    Programmer (String val) {
        name = val;
    }
    String getName() {
        return name;
    }
}
class Office {
    public static void main(String args[]) {
        new Programmer ("Harry").getName();
    }
}
The class Office prints Harry.
The derived class Programmer can’t define a getter method for a variable defined in its base class Employee.
The derived class Programmer can’t access variables of its base class in its constructors-.
  • new Programmer ("Harry").getName(); isn’t the right way to create an object of class Programmer.