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
private static int val ;
private String data;
public AnotherclassString s
i
data ;
;
public void joinString s
data data;
public void setDataString s
data ;
public String getData
return data;
public int getval
return val;
The following code segment appears in the main method of another class.
Anotherclass word new AnotherClass Hello;
word.join Hello;
AnotherClass sentence new AnotherClasswordgetData;
sentence.join Hi;
word.setData sentencegetData;
word.join Hello;
sentence.joinHi;
sentence.setData Hi;
System.out.printlnwordgetVal;
What is printed as a result of executing the code segment?
A
B
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
