|
-
Apr 30th, 2003, 07:20 PM
#1
Thread Starter
Lively Member
methods and classes
abstract super class with abstract method
subclasses with inherited methods defined
how do i access a method in the subsclass from the driver class (not from static main block)?
-
Apr 30th, 2003, 10:45 PM
#2
Dazed Member
You want to invoke a method that is defined in the abstract class that is inherited by a subclass? The class that is being derived from the abstract class must provide implementation for any abstract method prototypes defined in the abstract class otherwise it is too an abstract class. As long as the scope of the inherited methods is not narrowed then you should be fine.
Public and protected methods defined in your class should be able to be invoked outside of the class in which they are being defined in. I would use protected methods because non subclass in other packages cannot get to them. That should get you package scope.
-
May 1st, 2003, 01:13 AM
#3
Thread Starter
Lively Member
yes the subclasses have implementation of the abstract methods. but i'm still getting an error when i try:
otherClass.methodName();
ERROR:
Can't make static reference to method double methodName() in class otherClass
-
May 1st, 2003, 01:24 AM
#4
Dazed Member
Looks like you are trying to invoke a method via a class type rather than a refrence type which is fine as long as the method is defined in the class as static. An abstract class cannot define private, final and static methods since these methods cannot be overridden by a subclass. Similarly a final class cannot contain abstract methods because a final class cannot be extended and abstract methods contained in a class are meant to be inherited.
Last edited by Dilenger4; May 1st, 2003 at 01:29 AM.
-
May 1st, 2003, 04:30 AM
#5
An abstract class can define both static and final methods. static methods are very common in the class library, e.g. Toolkit.getDefaultToolkit().
It can define final methods too. Abstract classes are meant to be inherited, but the class might still have some implementation that must not be overridden. If an abstract class has no implementation you might as well make it an interface.
It can also define private methods for internal use.
But it cannot define an abstract final or abstract private method.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|