Question: Consider the following class declaration. public class Anotherclass { 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 Anotherclass String s
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 AnotherClassHello;
word.join Hello;
AnotherClass sentence new AnotherClass wordgetData;
sentence.joinHi;
word.setDatasentencegetData;
word.joinHello;
sentence.joinHi;
sentence.setDataHi;
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
