Results 1 to 2 of 2

Thread: Inheritance

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

    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
    Rep Power


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