Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Java please. Thanks Task 2: Understanding Programming Instructions: Answer each question below. Try to understand and explain the code. Do not put an IDE
In Java please. Thanks
Task 2: Understanding Programming Instructions: Answer each question below. Try to understand and explain the code. Do not put an IDE code screenshot. 1. Exercise 15: Suppose you have a class MyClass with one instance variablex. What will be printed by the following code segment? Myclass cl-new MyClass cl.3 MyClass c2 -cl c2.x4 System.out.println(cl.x)i Explain your answer 2. Exercile 16: Suppose a class has an instance variable x and a method with a local variable x Ifx is used in a calculation in the body of the method, which x is being referred to? a. b. Suppose you needed to add the local variable x to the instance variable x in the body of the method. How would you do so? 3. Exercise 17: The following method has a flaw (in fact, due to this flaw it will not compile). What is the flaw? void displayAbsxlint x) if (x >0) System.out-println (x) return System, out . printin {-x) return System, out . printin { "Done" ; 4. Exercise 18: Create a method max() that has two integer parameters x and y and returns the larger of x and y 5. Exercise 19: Create a method max() that has three integer parameters x, y, and z, and it returns the largest of the three. Do it two ways: once using an if-else-if ladder and once using nested if Statements. 6. Exercise 21: Find all the erors (f any) in the following class declaration: Class Myclass integer x3.0; boolean b false constructor MyClass (boolean b} { b-b; int doit() { int don'tDolt {} { return thisStep by Step Solution
There are 3 Steps involved in it
Step: 1
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