LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-11-2005, 03:49 AM   #1
hus
Member
 
Registered: Dec 2003
Location: Bangkok- Thailand
Distribution: Mandriva 10.0,Fedora Core 4
Posts: 79

Rep: Reputation: 15
Pass object variable to anothor class in JAVA


In JAVA

As I know it has two way to pass object (by reference) to
Anothor Class or Object

Code:
first >

class Test{
         JList list;

         Test(){
             list = new JList();
             new Test2(list);
         }

}

class Test2{

         JList list;
         Test2(JList list){
              this.list=list;
              list.doAnyThingYouWant();
         }
}

I call it that "pass via argument"
***************************************
and second >

class Test{
         public static JList list;

         Test(){
             list = new JList();
             new Test2();
         }

}

class Test2{

         Test2(){

              Test.list.doAnyThingYouWant();
         }
}
I call it that "pass via static variable"


first or second is more efficiency ?
and is it diffrence if it is ,how ?

Thanks in advance!

Last edited by hus; 05-11-2005 at 04:24 AM.
 
Old 05-11-2005, 03:55 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
I won't give an answer because the question is wrong.
You shouldn't consider efficiency in this matter; this is the VM's job.
What you have to decide here is the design. What really is list? What is its "life"? What will its evolution be? Are there synchronisation issues? And so on...

Yves.
 
Old 05-11-2005, 04:04 AM   #3
hus
Member
 
Registered: Dec 2003
Location: Bangkok- Thailand
Distribution: Mandriva 10.0,Fedora Core 4
Posts: 79

Original Poster
Rep: Reputation: 15
Hi theYinYeti

Sorry If my question is non sense.

But when I write a project that more than
500 lines I usually separate Class (interface) from
Class (Action) and usually refer to the member of
another class.
And I want to know the best way to drive my program
faster and more efficient
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Talk to an object in a diferent class bastl Programming 9 03-17-2005 01:36 PM
how pass a class to a function aditya1 Programming 2 03-08-2005 09:02 PM
java pass created class by refference true_atlantis Programming 4 01-10-2005 10:33 PM
C++ class-object? shivaligupta Programming 2 01-06-2005 02:25 AM
Event driven object-to-object: C++ template class mecanism ( NOT STL or STDC++) bretzeltux Programming 2 12-23-2003 02:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration