Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
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

Question

-12. Progra O https:/ Write a s I feel great today

Answered: 1 week ago