Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about sibling class

 
ravel chen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are four classes: A,B,C,D
code:
class A
{
void method(){}
}
class B extends A
{
void method(){}
}
public class C extends B
{
void method(){}
}
class D extends A{
void method(){}
}
In class D .
How can I use one or more words to call (sibling class)class B' method ?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't, without instantiating an instance of B.
 
C. Nimo
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
in class B - define
static void method(){}
in class D - use
B.method();

Nimo.
 
santhoshkumar samala
Ranch Hand
Posts: 156
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In class D you write
B b=new B();
b.method();
 
Gary Down
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Nimo's idea I think you have to make all the methods "static"
then
use B.method();
Perhaps a rethink on the design might be called for if your sole use of class "B" (or any of the others) is to access a hidden method.
[ April 29, 2004: Message edited by: Gary Down ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic