General Java Questions IV
the system crashes. I implemented it recently in one of our apps, and it works like a
charm.
   
Burt Johnson
MindStorm Productions, Inc.
http://www.mindstorm inc.com
 Q: Can you call a class static abstract method from an abstract class or does it
need to be extended and then called from its concrete class?
I ve been told that abstract classes do not actually have any code in them cause they
are like a placeholder, so I guess you wouldn t bother calling a static method in an
abstract class cause it wouldn t have any code to begin with....?
Answer: You have been told wrong. Abstract classes can and do have code in them.
See, for example, java.awt.Component, an abstract class with a lot of code and no
abstract methods at all. If a class has any abstract method member, directly declared
or inherited, it is required to be declared abstract. If not, it is the programmer s
decision and should be based on whether it would make sense to have an instance
of that class.
Perhaps whoever told you was confusing abstract classes with interfaces, which
don t contain implementation, only abstract method and constant declarations.
You cannot declare a method to be both static and abstract. Abstract requires the
method to be overridden before you can have a concrete class, static prevents
overriding. You can have a static method in an abstract class   such a method could
be called without creating an instance of the class, the only thing that is prohibited for
abstract classes.
And when a subclass of an abstract method has been instantiated, all the methods
from the original class will keep the same code in the instance. Most of the time an
abstract class will have abstract methods.
However, there are several examples of abstract classes that don t have any abstract
methods at all. Some examples are Component and FontMetrics from the AWT. It
doesn t make sense to have just a Component that s not a specific type of
component. It doesn t make sense to have a FontMetrics that doesn t measure any
specific kind of Font.
Also being abstract never prevents overriding, it just requires overriding in order to
derive a non abstract subclass. And if a class is a subclass of an abstract class, it
only MUST override those methods declared abstract. The other methods do not
require overriding.
 Q: I write java about 2 years, but I still confuse one thing that is why should we
use interface???
If I need to implement an interface and just use its every methods name.
Why shouldn t just write every methods statments in a class, not in interface??
I only can think about that if I extend a class, than can implement another or the
others interface.
As you can saw, I really confuse about this. And I do see many books for the reasons
, but I can t get the answer, please tell me !
Answer: "Interface" is the Java way to do multiple inheritance, or a better way to think
of it is as a way to design plug ins.
file:///F|/a_jsite/350_tips/general_java IV.htm (7 of 10) [2001 07 08 11:24:54]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved