Results 1 to 2 of 2

Thread: Inheritance

  1. #1
    mew
    mew is offline Member
    Join Date
    Nov 2007
    Posts
    70
    Rep Power
    0

    Default Inheritance

    I have the following situation.

    Class named ClassA extends from class named Master and will inherit all the methods of Master class. There are few methods, which should be available in child classes like in ClassA. How can I manage this?

    Java Code:
    public class ClassA extends Master{
    
    }
    Can inheritance be private?

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    The easiest way to find out is to make up a test app.
    Java Code:
    public class MasterTest {
        public static void main(String[] args) {
            Master master = new Master();
            A a = new A();
            // exercise/test your classes...
        }
    }
    
    class Master {
        String name;
    
        Master(String name) {
            this.name = name;
        }
    
        public void rideTheHorse() {
            System.out.println("riding the horse":
        }
    
        // other methods
        // try methods that return something
    
        public String toString() {
            return name;
        }
    }
    
    class A extends Master() {
        // call methods and access fields of superclass
    }
    Can inheritance be private?
    Possibly, depends on what you have in mind. We have the private access modifier and the final keyword available. Play with them in your test app.

Similar Threads

  1. inheritance and aggregation
    By java_fun2007 in forum New To Java
    Replies: 3
    Last Post: 12-13-2007, 01:36 PM
  2. Delegation vs inheritance
    By javaplus in forum Advanced Java
    Replies: 1
    Last Post: 12-07-2007, 09:07 PM
  3. Multiple Inheritance
    By mew in forum New To Java
    Replies: 1
    Last Post: 12-01-2007, 10:04 PM
  4. Inheritance in GUI
    By Marty in forum SWT / JFace
    Replies: 2
    Last Post: 05-11-2007, 12:54 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
  •