Question: Consider the following class declaration. public class Anotherclass 1 private static int val = 3 1 ; private String data; public Anotherclass ( String s

Consider the following class declaration.
public class Anotherclass
1
private static int val =31;
private String data;
public Anotherclass(String s)
i
data =s;
val?=2;
}
public void join(String s)
data =data+s;
public void setData(String s)
data =s;
public String getData()
{ return data; }
public int getval()
{ return val; }
}
9. The following code segment appears in the main method of another class.
Anotherclass word = new AnotherClass ("Hello");
word.join ("Hello");
AnotherClass sentence = new AnotherClass(word.getData());
sentence.join ("Hi");
word.setData (sentence.getData());
word.join ("Hello");
sentence.join("Hi");
sentence.setData ("Hi");
System.out.println(word.getVal());
What is printed as a result of executing the code segment?
(A)30
(B)15
 Consider the following class declaration. public class Anotherclass 1 private static

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!