public course Human //human stuffpublic class Developer expand Human //developer stuffWhy is Developer an circumstances of Human, but the course Developer is not assignable to Human?

Developer dev = brand-new Developer();System.out.println(dev instanceof Human); //trueSystem.out.println(Developer.class.isAssignableFrom(Human.class)); //falseBut in enhancement to this: person is assignable to Developer.

You are watching: A instance of a subclass is also an instance of its superclass.

System.out.println(Human.class.isAssignableFrom(Developer.class)); //trueIn typical English I would certainly say the a Developer thing is assignable indigenous a human being class, not the other way around.



If you intend there is a role assignableTo, this is that you say but assignableFrom is reverse:

The java.lang.Class.isAssignableFrom() determines if the class or interface represented by this class object is one of two people the same as, or is a superclass or superinterface of, the class or user interface represented through the specified class parameter.

You deserve to learn much more enter this


A Developer is-a Human, however not every human being is-a developer.

Inheritance imposes an is-a relationship on that children. This method that a kid can constantly be determined by their parent class, but a parental isn"t proven or demonstrated to be i can identify by their child.

In a nutshell, this is what isAssignableFrom is demonstrating; you"re wonder if a person is assignable native a Developer, i beg your pardon isn"t true. That type of assignment would certainly be Developer dev = new Human();, which just works the other method "round (i.e. Person human = brand-new Developer();).


Human.class.isAssignableFrom(Developer.class)in English means: you can assign come a change of the person class things of the Developer class.


In normal English I would certainly say, the a developer thing is assignable indigenous a person class, no the other way around.

And the trouble is your intake of the native "object" and also "class" here. It must be: a human variable is assignable indigenous a value of form Developer.

You assign a value to a variable from analyzing an expression.

You deserve to do:

Human human = brand-new Developer()But you can not do:

Developer developer = brand-new Human()In logical terms, every developer is a human being not every human is a developer.

If you had actually a class QaEngineer that would certainly inherit from human you won"t desire this to be allowed:

Developer developer = new QaDeveloper()or this:

Developer developer = (Human) new QaDeveloper()
from the documentation of the method

Determines if the course or interface represented by this class object is either the same as, or is a superclass or superinterface of, the course or user interface represented by the specified course parameter.<...>

So basicly the method returns, if the parameter class noted is the same course or interface, or a subclass or subinterface the the course it was invoked on.

Developer.class.isAssignableFrom(Human.class) // False, Developer is not a superclass that HumanHuman.class.isAssignableFrom(Developer.class) // True, human being is a superclass of Developer
Try come think it choose this:

Human.class.isAssignableFrom(Developer.class) //true; method you deserve to assign a developer object in reference of Human.

Developer.class.isAssignableFrom(Human.class) //false;means you deserve to not assign an item of Human course (parent) in the reference of Developer course (child). The core dominion is that: You deserve to assign an object of son to recommendation of parent, no the other method round.

Hope it helps.

Thanks because that contributing response to ridge Overflow!

Please be certain to answer the question. Provide details and also share your research!

But avoid

Asking for help, clarification, or responding to various other answers.Making statements based on opinion; earlier them up with references or an individual experience.

See more: Identify The Bone Of The Lower Limb That Bears The Least Amount Of Weight.

To learn more, watch our advice on writing great answers.

short article Your answer Discard

By click “Post her Answer”, you agree to our terms of service, privacy policy and also cookie plan

Not the prize you're feather for? Browse various other questions tagged java or asking your own question.

site style / logo © 2021 ridge Exchange Inc; user contributions licensed under cc by-sa. Rev2021.11.12.40736

your privacy

By clicking “Accept all cookies”, girlfriend agree stack Exchange have the right to store cookie on your maker and disclose information in accordance through our Cookie Policy.