Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the output of running the following code? public class Test public stati

ID: 3708465 • Letter: W

Question

What is the output of running the following code? public class Test public static void main(Stringl args int b 5; int ar 5,4, 3, 2 double valmyMethod(b, ar), System.out printin(val ar[2]b) public static double myMethod(double b, int arrD)k b 1.0 arr[2](int)(arr1]*b); return b O 4.0, 16, 5 O 4.0, 16, 4 O 4.0, 16,-1 O 4, 3,4 4, 20,5 Which is following is false about constructors O Constructors are not needed O Constructors are there by default. Even if you dont' see it. O Constructors can be overloaded All Constructors are public

Explanation / Answer

(1)

Value of b is initially 5. arr[1] is 4, arr[2] is 3

With in the method myMethod:
  
   Local variable b is updated as b = 5.0 - 1.0 => b = 4.0
   arr[2] = (int)(4*4.0) => arr[2] = (int)(16.0) => arr[2] = 16
  
   Value of b is returned back and stored in variable val in main method.
  
So the values of val, ar[2] and b are: 4.0, 16, 5 respectively

Hence correct option is (1)

_____________________________________________________________________________________________

(2)

    A Constructor is a method with name same as that of class name and gets invoked when ever creating an object.
  
   Constructor's are needed to initialize values to variables and also to allocate memory to variables.
  
   Hence False about constructors is that: Constructors are not needed.

______________________________________________________________________________________________

(3)

Syntax for inheriting a base class by a child class is:

class <Child> extends <Base>

Hence correct option is

class B extends A

_______________________________________________________________________________________________

(4)

    The major difference between While and Do-While loop are:
  
   While loop is an Entry Level Condition check. First checks the condition and only the code gets executed.

   Do-While loop is an Exit Level Condition check. First executes the code atleast once and then checks for condition.
  
   Do-While loop is guaranteed to run at-least once.
  
   Hence correct option is:
  
   While loop tests condition before execution. Do-While loop tests condition after execution

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote