Read codes and answer questions. //MyClass.java package cn.zjnu.exams; public class MyClass { private int count; String...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
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... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these accounting questions
-
What is the return on investment (ROI) on investments in corporate wellness programs? What are the nonfinancial returns on such investments? The following article addresses the notion of...
-
What is the return on stockholders' equity (after tax) ratio?
-
What is the return on assets ratio?
-
DBU Systems manufactures testing equipment for the communications industry. In developing a new device for maritime communication, the design group has estimated the following unit costs. Metal...
-
How do employees perceptions of fairness affect motivation?
-
The pie chart shows an overview of the world?s total land area with respect to its suitability for agriculture. How could soil that is too dry for agriculture be converted to cropland? How could soil...
-
Construct a 95% confidence interval for 1. Exercises 610 refer to the following data set: x 25 13 16 19 29 19 16 30 y 40 20 33 30 50 37 34 37
-
Faldo Company produces a single product. The projected income statement for the coming year, based on sales of 200,000 units, is as follows: Sales ........... $2,000,000 Less: Variable costs .......
-
If fixed costs are $1,480,000, the unit selling price is $230, and the unit variable costs are $123, what is the break-even point in sales units if fixed costs are increased by $47,400?
-
What are the triads using roman numerals and figured bass numbers for this excerpt? 30-3. Use Roman numerals and figured bass numbers to identify triads in these works. a. Schubert, "Death and the...
-
What is the Cabinet?
-
During trials of a new submarine, its speed is measured with an underwater sonar gun anchored to the ocean floor. The gun emits sound waves at a frequency \(f\), and these waves reflect off the...
-
Either a dielectric or a conductor could be inserted between the plates of a capacitor. (a) State at least two similarities between the effects of inserting a dielectric and inserting a conducting...
-
A harmonic wave traveling along a light string approaches a splice to a heavier string, as shown in Figure P16.16. Which changes as the wave crosses the boundary: wavelength, frequency, both, or...
-
Two sinusoidal waves travel in opposite directions along the same string. The wavelength and frequency are the same in both waves, and each has amplitude \(0.0289 \mathrm{~m}\). If there is a phase...
-
Two sinusoidal waves travel along the same string. Their time-dependent wave functions are \[\begin{aligned} & f_{1}(x, t)=a \sin \left(b x-q t-\frac{1}{4} \pi ight) \\ & f_{2}(x, t)=a \sin \left(b...
-
Masters Gadgets Company (MGC) produces power supply units for the gamer desktop computers. You (production planner) are assigned the job of developing an aggregate production plan for the six months...
-
Using (1) or (2), find L(f) if f(t) if equals: t cos 4t
-
An ISBN-10 (International Standard Book Number) consists of 10 digits: d 1 d 2 d 3 d 4 d 5 d 6 d 7 d 8 d 9 d 10 . The last digit, d 10 , is a checksum, which is calculated from the other nine digits...
-
Modify MyHashMap to allow duplicate keys for entries. You need to modify the implementation for the put(key, value) method. Also add a new method named getAll(key) that returns a set of values that...
-
In a game of tic-tac-toe, two players take turns marking an available cell in a 3 ? 3 grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal,...
-
Briefly explain the connections between values such as effort optimism, utilitarian individualism, and the American economic system. Throughout this chapter, we have identified culture as something...
-
Do you speak a language other than English as a first language? If so, do you want your children and grandchildren to speak that language? In the United States, the tools of government and education...
-
If English is your first language, did your parents or grandparents speak a different first language? How do you feel about your ability (or lack of ability) in that language? In the United States,...
Study smarter with the SolutionInn App