Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use another class in one class

Status
Not open for further replies.

WebGoat

MIS
Jul 16, 2005
85
US
Code:
class ABC
{

public static void main(String args[])
{


}


}

class DEF
{
private ABC abc;

setMethod()
{
// i want to use abc here. How ?

}

getMethod()
{

// i want to use abc here. How ?

}



}
 
In your main, presumably you have something like: abc = new ABC();, yes? To create a DEF object, then:

Code:
DEF def = new DEF(abc);

...and in your DEF class definition:

Code:
public DEF(ABC abc)
{
 this.abc = abc;
}//end overriding constructor

Then in your DEF methods, you can use the abc variable.

Is that what you mean?

'hope that helps.

--Dave
 
I think WebGoat needs to provide more information about how the class will be used, but a first sight you just need to do

Code:
abc.main();

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top