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 publicExplanation / 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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.