Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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 =31;
private string data;
public Anotherclass (String s)
{
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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions