Click here to Skip to main content
15,117,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am learning awt and i am confused in java hierarchy.
So since java.lang imported by default and it contains Object class.
Object class is base class to all class.

So when lang package is imported by default, will all the derived class of object class be also imported ?

What I have tried:

tried seeing oracle documentation of hierarchy.
read about import keyword.
Posted
Updated 29-May-21 23:29pm

No.
Objects know about things they are derived from, all the way back to object - but no class should know about anything that is derived from it.
So if ClassA derives from ClassB, and ClassC derives from ClassA, then:
ClassC can use anything in ClassA or ClassB
ClassA can use anything in ClassB, but nothing from ClassC
ClassB cannot use anything from ClassA or ClassB


Extending that to language packs - everything derives from Object - but that means Object cannot access anything in any other class. So how could java.lang import "every other class" that could possibly be created and derived from Object?
java.lang contains just the basics - stuff nearly every program is going to need - it does not contain "specialised classes" that are imported from their own packages: java.lang (Java SE 11 & JDK 11 )[^]
   
Why have you reposted this question? I gave you a link to the answer yesterday at Can you explain package hierachy in java.[^].

I suggest that before you try to learn awt you spend time learning Java and the inheritance rules, starting with Lesson: Object-Oriented Programming Concepts (The Java™ Tutorials > Learning the Java Language)[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900