My guess is that the variable pete
is declared as class Employee
, which means that only methods of that class can be called on that variable. You must either declare pete
as type Worker
, or use a cast:
((Worker)pete).work(5);
More Related Contents:
- Overriding vs Hiding Java – Confused
- In Java, how do I call a base class’s method from the overriding method in a derived class?
- Java Inheritance – calling superclass method
- Java: How to find if a method is overridden from base class? [duplicate]
- get Index of last Element in list without using lastIndexOf() or any other Java/String- Methods [closed]
- Difference between Inheritance and Composition
- Do subclasses inherit private fields?
- Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed?
- Is there a way to override class variables in Java?
- Why do we assign a parent reference to the child object in Java?
- Inheritance in Java – creating an object of the subclass invokes also the constructor of the superclass. Why exactly?
- Is polymorphism possible without inheritance?
- Advantage of set and get methods vs public variable [duplicate]
- can’t cast to implemented interface
- How can a derived class invoke private method of base class?
- Builder Pattern and Inheritance
- Return multiple values from a Java method: why no n-tuple objects?
- What does the return keyword do in a void method in Java?
- Optional Methods in Java Interface
- Java method overriding and variable shadowing
- Can methods in java be nested and what is the effect? [closed]
- java.lang.NullPointerException with boolean
- When do instance variables get initialized and values assigned?
- Does an instance of superclass get created when we instantiate an object?
- Anonymous vs named inner classes? – best practices?
- Can there exist two main methods in a Java program?
- Java overloading and inheritance rules
- Abstract methods in Java
- What are the negative aspects of Java class Stack inheriting from Vector?
- If a synchronized method calls another non-synchronized method, is there a lock on the non-synchronized method