calling methods from a chain inheritance program

jhh

I wrote a program consisting of 3 classes and a main class, the 3 classes going through inheritance chain(Employee, Teacher extends Employee, MathTeacher extends Teacher). I've constructed an ArrayList for employees. so I'm trying to call a method from the MathTeacher class in the main class (concerning the ArrayList) but I can call nothing but the Employee class methods . any advice?

Edit: I'm undergraduate, new to the Inheritance chapter.

Adrian Russo

By typecasting an item from the array into the MathTeacher object, you can use the methods from this class, not just those from Employee. For example:

((MathTeacher) arrayList.get(0)).mathTeacherMethod();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Python

Inheritance - Calling methods within methods

From Dev

Calling different methods from different traits in scala with multiple inheritance

From Dev

Multiple Inheritance and calling methods from different parents with the same name

From Dev

Class inheritance - properly calling methods

From Java

Calling methods reflectivly or using fixed methods with inheritance?

From Dev

Python Inheritance: Calling Methods Inside Methods

From Dev

Proper/easy way of calling methods from a program on remote server in java?

From Dev

Calling Java Methods from JNI results in program crash

From Dev

Container class and calling virtual methods with inheritance

From Dev

Chain inheritance

From Dev

Calling python from perl - methods are not calling properly

From Dev

Calling methods from module in class

From Dev

Calling methods and closures from an array

From Dev

Django calling methods from models

From Dev

Calling Swift Methods from AppleScript

From Dev

Calling JavaScript methods from typescript

From Dev

Calling methods from different threads

From Dev

Calling superclass methods from a subclass

From Dev

Trouble calling methods from a class/

From Dev

Calling a function in program from a dictionary

From Dev

Calling minizinc from cpp program

From Dev

Calling a program from another in python

From Dev

How and why inheritance of methods differ from inheritance of variables?

From Dev

c++ Getting access to member outside from inheritance chain

From Dev

JavaScript native inheritance chain

From Dev

Prototype Chain Inheritance

From Dev

Trying to understand the inheritance chain

From Dev

Prototypal inheritance chain with JavaScript

From Dev

Inheritance chain with optional parameter

Related Related

HotTag

Archive