Question: 7 . Consider the following code where a String variable is passed to a method. The method changes the value of its parameter then returns.

7. Consider the following code where a String variable is passed to a method. The method changes the
value of its parameter then returns. Is the String changed when you return from the method call? If not,
why not?
String str1= "Hello";
changeString(str1);
System.out.println(str1);
...
public void changeString(String str1)
{
str1="Goodbye";
}
8. Consider the following code where a reference to a Button object is passed to a method. The method
changes the label of the button then returns. Is the Label of the Button changed when you return from
the method call? If not, why not?
JButton btn1=new JButton("Hello");
changeLabel(btn1);
System.out.println(btn1.getText());
...
public void changeLabel(JButton btn1)
{
btn1.setText("Goodbye");
}
9. The following code produces an exception. What would you do to fix it?
String[] array1;
array1[0]="Hello";
array1[1]="Goodbye";

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!