aspose file tools*
The moose likes Beginning Java and the fly likes A question about sibling class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A question about sibling class" Watch "A question about sibling class" New topic
Author

A question about sibling class

ravel chen
Greenhorn

Joined: Mar 03, 2004
Posts: 3
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

You can't, without instantiating an instance of B.


[Jess in Action][AskingGoodQuestions]
C. Nimo
Ranch Hand

Joined: Mar 23, 2004
Posts: 82
Hi.
in class B - define
static void method(){}
in class D - use
B.method();

Nimo.
santhoshkumar samala
Ranch Hand

Joined: Nov 12, 2003
Posts: 156

In class D you write
B b=new B();
b.method();


santhosh<br />SCJP,SCWCD
Gary Down
Ranch Hand

Joined: Apr 09, 2004
Posts: 46
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question about sibling class