Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

subclass question

 
Mike Cunningham
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it true that all classes that we create are subclasses since all programs automatically import the java.lang package?
Someone I work with said this was wrong since sometimes he is able to compile a class without the java.lang import and other times, it is required.
Please Clarify. Thanks.
 
Guoqiao Sun
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Mike :
Java compiler will automatically import java.lang.*;
And all class we create are subclass of Object.
Regards,

------------------
Guoqiao Sun
Sun Certified Programmer for Java™ 2 Platform
try my mock exam¹²³ at my homepage.
 
Guoqiao Sun
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget one point, the compiler will automatically import java.lang.*; That does not mean it will automatically import every sub package in lang. Example:
import java.lang.reflect.InvocationTargetException;
if you want to use the above class, you should import it explicitly although it is inside lang.
Regards,
------------------
Guoqiao Sun
Sun Certified Programmer for Java™ 2 Platform
try my mock exam¹²³ at my homepage.
 
Fei Ng
Ranch Hand
Posts: 1244
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do u mean "Is it true that all classes that we create are subclasses since all programs automatically import the java.lang package? "
All classes that we create are subclasses since..
subclasses of ???
I dont think automatically import the java.lang got anything
to do with classes we create are subclasses.
???
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is true that all classes that we create are subclasses (of class Object), and it is true that the java.lang package is automatically imported every time (although the subpackages are not automatically imported).

However, it is not true that "all classes that we create are subclasses since all programs automatically import the java.lang package" because these two statements are unrelated.
 
Mike Cunningham
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, does a class need to 'extend' another class to officially be a subclass?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic