Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Read codes and answer questions. //MyClass.java package cn.zjnu.exams; public class MyClass { private int count; String info; public static String message = Good; public
Read codes and answer questions. //MyClass.java package cn.zjnu.exams; public class MyClass { private int count; String info; public static String message = "Good"; public MyClass increase() { count++; //return the current object 1/3 } private MyClass() { this.count=0; public int getCount() { return count; } public static MyClass getInstance() ( // Create and return the object of MyClass 2 } this.info= "Good Luck"; //TestMyClass.java package cn.zjnu.exams; public class TestMyClass { public static void main(String[] args) { MyClass mc1 = MyClass.getInstance(); MyClass mc2 = MyClass.getInstance(); mc1.message = "Great"; mc2.message = "Excellent"; MyClass.message = "Nice"; } System.out.println(mc1.message":"+mc2.message+:+MyClass.message); // 3.1 //3.2 3.3 3.4 System.out.println(mc1.info==mc2.info); mc2.info= new String("GoodLuck"); System.out.println(mc1.info==mc2.info); System.out.println(mc1.info.equals (mc2. info)); System.out.println(mc1.increase().increase().getCount());//3.4 Questions: 1) 2) 3) What is the output of the code? Explain the reason. 3.1 3.2 //3.3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Line 31 This line creates two instances of the MyClass class using the getInstance method However the implementation of this method is not shown so it...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started