Results 1 to 2 of 2
  1. #1
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default Calling base class methods

    Let's say I have the following 3 classes. Class C extends B, and B extends A.
    Is it possible within C to call A's mothod myMethod()? If so, how?

    Thanks!
    --------------

    class A {
    public void myMethod()
    {
    /* ... */
    }
    }
    class B extends A {

    }

    class c extends B {
    // Can I call class A's myMethod()?
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default Re: Calling base class methods

    Not directly. A class can call a method in the parent class by using the super keyword. So you would need class C to call a method in class B which would call a method in class A. However, if you plan on creating methods just to facilitate this then I have to question your design and what you are trying to do.

Similar Threads

  1. Replies: 3
    Last Post: 09-29-2010, 09:26 AM
  2. Calling methods into another class? Help please!
    By javanator in forum New To Java
    Replies: 1
    Last Post: 03-20-2010, 06:19 PM
  3. 'Class' Object and calling Static Methods?
    By mikeiz404 in forum Advanced Java
    Replies: 3
    Last Post: 01-24-2009, 12:58 PM
  4. 'Class' Object and calling Static Methods?
    By mikeiz404 in forum New To Java
    Replies: 2
    Last Post: 01-24-2009, 05:10 AM
  5. need help calling methods
    By lowpro in forum New To Java
    Replies: 2
    Last Post: 11-15-2007, 09:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •