| Author |
Difference between extending class, importing package
|
Keyur Jinwala
Greenhorn
Joined: Jun 14, 2007
Posts: 3
|
|
What is the difference between extending a class and importing it as a package. If I want to extend class A, can I write import A? What would be its impact compared to extending it?
|
 |
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
|
|
Originally posted by Keyur Jinwala: What is the difference between extending a class and importing it as a package. If I want to extend class A, can I write import A? What would be its impact compared to extending it?
Importing a class and extending a class are two different concepts.Poles apart .You have to import to make the class visible and you use extends for inheritance purpose.
|
Rahul Bhattacharjee
LinkedIn - Blog
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
[Definitely a beginner question - moderator may like to move it]. Importing a class is purely a syntactic convenience. It just saves you from typing the package in front of every class name. Importing has no effect on semantics: if you didn't import anything and instead wrote out all class names in full, with their packages, the program would behave identically. Extending a class is a completely different concept and one of the fundamentals of object orientation. [ July 18, 2007: Message edited by: Peter Chase ]
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9948
|
|
To put it more simply, when you import a package, you're basically telling the compiler "hey, if you don't know what some class is, you might find it in THIS place". that's all you're doing. if you never used imports, you would have to do things like: com.foobar.foo.bar.MyClass myVariable = new com.foobar.foo.bar.MyClass(); with imports, you do this (after using the import statement): MyClass myVariable = new MyClass();
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
 |
|
|
subject: Difference between extending class, importing package
|
|
|