The Artima Developer Community
Sponsored Link

Java Answers Forum
passing object type as paramter to method from one call to another

1 reply on 1 page. Most recent reply: Apr 13, 2002 10:58 AM by Jay Kandy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Nayan

Posts: 1
Nickname: nrjava
Registered: Apr, 2002

passing object type as paramter to method from one call to another Posted: Apr 13, 2002 10:25 AM
Reply to this message Reply
Advertisement
i need to call a method (which takes the Test object as it's parameter) in
AnotherTest.java , from a method that exists in the Test.java. how can i
dothis ? i put up a hypotetical code since the real one may look tedious.
please respond if you have any thoughts on how to work with this ?

Thanks a bunch in advance.

Public class Test {
//declarations
//constructor
// methods
public method_1 {
// body of the method 1
// i need to invoke method2 from AnotherTest here passing MyTest as
parameter
}

public static void main(String args[]) {
Test MyTest = new Test();
}
}


Public class AnotherTest {
//constructor
public method2 (Test MyTest) {
// work with some of the methods and public variables that exist in Test
}
}


Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: passing object type as paramter to method from one call to another Posted: Apr 13, 2002 10:58 AM
Reply to this message Reply
Heres the code with some minor changes like printlns.

An Inner class seems like a better choice to me. (Expecially when AnotherTest is declared public)
/**
 *        Test.java
 */
public class Test
{
	//declarations
	//constructor
	// methods
	public void method_1()
	{
		// body of the method 1
		// i need to invoke method2 from AnotherTest here passing MyTest as parameter
		new AnotherTest().method2(this);
 
		System.out.println( "{method_1}" );
	}
 
	public static void main(String args[])
	{
		Test MyTest = new Test();
		MyTest.method_1();
	}
 
	public String toString()
	{
		return "[Test]";
	}
}
 
/**
 *        AnotherTest.java
 */
public class AnotherTest
{
	//constructor
	public void method2(Test MyTest)
	{
		// work with some of the methods and public variables that exist in Test
		System.out.println( MyTest );
		System.out.println( "{method2}" );
	}
 
	public String toString()
	{
		return "[AnotherTest]";
	}
}

Sincerely,
Jay

Flat View: This topic has 1 reply on 1 page
Topic: How a request a key from my keyborad Previous Topic   Next Topic Topic: Dll to JSp

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use