Geoffrey Gulack
Geoffrey Gulack

Reputation: 11

How to get Class Name in an Inheritance Structure

I'm trying to get the Class Name of a abstract Child class from a Parent class object.

public abstract class Employee  
public abstract class Faculty extends Employee
public class Professor extends Faculty

Employee bob = new Professor();

How do I get Faculty useing one of the .getName(), .getSimpleName() or similar method from the bob object?

Upvotes: 0

Views: 6608

Answers (2)

Khalil
Khalil

Reputation: 259

Try this bob.getClass().getSuperclass()

Upvotes: 2

Rodney G
Rodney G

Reputation: 4826

You are probably looking for bob.getClass(). You can also use if bob instanceof Faculty.

Upvotes: 1

Related Questions