Results 1 to 2 of 2
Thread: Inheritance
- 12-07-2007, 01:10 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 70
- Rep Power
- 0
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{ … }
- 12-07-2007, 07:08 PM #2
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 }
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
-
inheritance and aggregation
By java_fun2007 in forum New To JavaReplies: 3Last Post: 12-13-2007, 02:36 PM -
Delegation vs inheritance
By javaplus in forum Advanced JavaReplies: 1Last Post: 12-07-2007, 10:07 PM -
Multiple Inheritance
By mew in forum New To JavaReplies: 1Last Post: 12-01-2007, 11:04 PM -
Inheritance in GUI
By Marty in forum SWT / JFaceReplies: 2Last Post: 05-11-2007, 01:54 AM
Bookmarks