Results 1 to 3 of 3
- 07-29-2012, 01:30 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 4
- Rep Power
- 0
Access child methods from parent class
Let's say I have for example:
Is it possible to access child methods from parent class?PHP Code:abstract class A { public A() { B b = newB(); b.test(); } abstract class B { void test() { } } } Class B extends A { class B extends A.B { void test() { // i want to access this from parent class A } } } A = new A;...
EDIT: sorry not method but child class so:
when i run this the extended part is not executed i get instance of parent inner classPHP Code:abstract class A { public A() { B b = newB(); } abstract class B { } } Class B extends A { class B extends A.B { void A.B() { // i want to access this from parent class A } } } A = new A;...Last edited by bmL; 07-29-2012 at 01:41 PM.
- 07-29-2012, 01:36 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Access child methods from parent class
Nope; and in your example you can't even create an A because class A is abstract. Why do you want such artificial class hierarchies? Is it an assignment?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-29-2012, 02:25 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 4
- Rep Power
- 0
Re: Access child methods from parent class
I want one abstract class which implements most of functionality so specialized classes need only to implement specialized things. Right now im doing something like this:
and it does just fine. But i would like to get rid of the getB method and keep it functioning so I dont have to reimplement the A.addNotify just to call add(new B()); in every specialized class.PHP Code:abstract Class A { addNotify() { add(getB()); } abstract B getB(); abstract Class B { } } abstract class C extends A { B getB() { return new B(); } class B extends A.B { } }
Similar Threads
-
Please help me. Parent and Child Class with Swing
By paul6lazo in forum AWT / SwingReplies: 22Last Post: 09-07-2011, 05:37 PM -
Access Parent and child node
By emyk in forum Advanced JavaReplies: 0Last Post: 05-02-2011, 11:16 PM -
substract Parent class object from child class
By nikosv in forum New To JavaReplies: 0Last Post: 12-08-2010, 12:30 AM -
Child-Class Calling a Method in a Parent-Class
By Blah_ in forum New To JavaReplies: 5Last Post: 09-29-2009, 02:48 AM -
[SOLVED] How to pass information from child class to parent class
By pellebye in forum New To JavaReplies: 7Last Post: 05-06-2009, 12:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks