Results 1 to 5 of 5

Thread: methods and classes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103

    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)?

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103
    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

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width