-3

I've been using getters and setters in this java code .. so in my Class A I get the user input and I tried this and it runs perfect and I tried to output the user input and the answer is same so I've go to the Class B in class B I need to search .. the user will search and output the answer if true .. in class A

example the user input Student id : 12 and he searched it in class B it must output ..

but my problem I don't know how I can link the array from the Class A to Class B so I can manage to search is ..

  • What do you mean by "link the array". Can you post some code for A and B showing us what you are trying to do? –  Aug 04 '15 at 05:41
  • Check this, maybe it will help you > http://stackoverflow.com/questions/16462163/java-how-to-access-an-arraylist-of-another-class – newuserua_ext Aug 04 '15 at 05:42
  • System.out.print("ENTER NAME: "); mskt[rec.a].setName(br.readLine()); System.out.print("ENTER ID: "); mskt[rec.a].setId(Integer.parseInt(br.readLine())); System.out.print("ENTER MATH GRADE: "); //i ask the user to input and store the value at int a .. int a is declared as global .. i want to search =its values in class B – Joshua Gonzales Aug 04 '15 at 05:42
  • 3
    Please don't try to put this much code in a comment. Edit your question and add the code there. – ajb Aug 04 '15 at 05:47
  • sorry sir im just new in this forum – Joshua Gonzales Aug 04 '15 at 05:52
  • I suggest you add all the relevant code to your post. You will get better help faster if it's possible to "see" what you're doing. – ChiefTwoPencils Aug 04 '15 at 05:55
  • i declared this : rec[] mskt=new rec[10]; and mskt[rec.a]=new rec(); in my class A ?? // rec is my class and mskt is my object .. i dont know how can i access this on Class B ?? so i can use it to search and what should i declare on class B ? – Joshua Gonzales Aug 04 '15 at 05:58
  • Why do you insist on not editing your post? Add your code to your post as it is please! – ChiefTwoPencils Aug 04 '15 at 06:18

1 Answers1

0

You can pass an array to a method call, like this:

// void someMethod(String[] someStringArray);
String[] theArray = new String[]{"foo", "bar"};
someMethod(theArray);

or to some constructor:

// SomeClass(String[] someStringArray);
String[] theArray = new String[]{"foo", "bar"};
SomeClass foobar = new SomeClass(theArray);

see also, this tutorial

  • in class A i declared this :rec[] mskt=new rec[10]; mskt[rec.a]=new rec(); /rec is the class name , mskt is object name .. im not sure how can i access this in class B ? – Joshua Gonzales Aug 04 '15 at 05:50