Click to See Complete Forum and Search --> : methods and classes
quipy
Apr 30th, 2003, 08:20 PM
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)?
Dillinger4
Apr 30th, 2003, 11:45 PM
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.
quipy
May 1st, 2003, 02:13 AM
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
Dillinger4
May 1st, 2003, 02:24 AM
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.
CornedBee
May 1st, 2003, 05:30 AM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.