concept derive class in category java

appears as: derived class, derived classes, A derived class, derived classes, A derived class, The derived class, derived class
Java SE 11 Programmer I Certification Guide MEAP V03

This is an excerpt from Manning's book Java SE 11 Programmer I Certification Guide MEAP V03.

An abstract method doesn’t have a body. Usually, an abstract method is implemented by a derived class. Here’s an example:

Figure 10.6 An object of a derived class can access features of its base class object.

But a derived class can’t inherit all the members of its base class. The next two sections discuss which base class members are and aren’t inherited by a derived class.

Although derived classes are similar to their base classes, they generally also have differences. Derived classes can define additional properties and behaviors. You may see explicit questions on the exam about how a derived class can differ from its base class.

Take a quick look back at figure 10.5. All the derived classes—Manager, Programmer, Doctor, and Astronaut—define additional variables, methods, or both. Derived classes can also define their own constructors and static methods and variables. A derived class can also hide or override its base class’s members.

When a derived class defines an instance or class variable with the same name as one defined from its base class, only these new variables and methods are visible to code using the derived class. When a derived class defines different code for a method inherited from a base class by defining the method again, this method is treated as a special method—an overridden method.

OCA Java SE 8 Programmer I Certification Guide

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

Purpose: This question is an example of a simple concept (private members are not accessible to a derived class) that is made to look complex by including code and options that try to divert your attention. Expect similar questions on the exam.

Figure 6.6. An object of a derived class can access features of its base class object.

But a derived class can’t inherit all the members of its base class. The next two sections discuss which base class members are and aren’t inherited by a derived class.

6.1.6. Derived classes can define additional properties and behaviors

Although derived classes are similar to their base classes, they generally also have differences. Derived classes can define additional properties and behaviors. You may see explicit questions on the exam about how a derived class can differ from its base class.

Take a quick look back at figure 6.5. All the derived classes—Manager, Programmer, Doctor, and Astronaut—define additional variables, methods, or both. Derived classes can also define their own constructors and static methods and variables. A derived class can also hide or override its base class’s members.

When a derived class defines an instance or class variable with the same name as one defined from its base class, only these new variables and methods are visible to code using the derived class. When a derived class defines different code for a method inherited from a base class by defining the method again, this method is treated as a special method—an overridden method.

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-.

6.1.4. Which base class members are inherited by a derived class?

The access modifiers play an important role in determining the inheritance of base class members in derived classes. A derived class can inherit only what it can see. A derived class inherits all the nonprivate members of its base class. A derived class inherits base class members with the following accessibility levels:

  • Default—Members with default access can be accessed in a derived class only if the base and derived classes reside in the same package.
  • sitemap

    Unable to load book!

    The book could not be loaded.

    (try again in a couple of minutes)

    manning.com homepage
    test yourself with a liveTest