-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 ..

8
  • 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? Commented Aug 4, 2015 at 5:41
  • Check this, maybe it will help you > stackoverflow.com/questions/16462163/… Commented Aug 4, 2015 at 5: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 Commented Aug 4, 2015 at 5:42
  • 3
    Please don't try to put this much code in a comment. Edit your question and add the code there. Commented Aug 4, 2015 at 5:47
  • sorry sir im just new in this forum Commented Aug 4, 2015 at 5:52

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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 ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.