30. Suppose sum and num are int variables, and the input is 15 18 20 -1
What is the output of the following code? (Assume that console is a scanner object initialized to the standard input device.)
sum = console.nextInt();
num = console.nextInt();
while (num != -1) {
num = console.nextInt();
sum = sum + num;
}
System.out.println(sum);
a. 34 b.35 c.52 d.53
57. Which of the following statements would you use to declare the reference variable secretObject of type Secret and instantiate the object such that the value of the data member x is 7 and the value of the data member z is 10?
a. Secret secretObject = new Secret (7, 10);
b. Secret secretObject = new Secret (10, 7);
c. Secret secretObject(7);
d. Secret.secretObject(10);
30) a)34
Reason:
Initially
sum=15
num=18
In while loop as 18!=-1
num=20
sum=15+20
In while loop as 20!=-1
num=-1
sum=35-1
Hence, sum has 34
57) a) Secret secretObject = new Secret (7, 10);
Reason:
Assuming that x is followed by z in the class,
we instantiate the object with data members as
classname objname = new classname(values);
So, from available options a) is the correct answer
Hope it helps! If there are any doubts or discrepancies do comment below! We are available!:) Give your valuable upvote if you are satisfied with the answer!:))))
Get Answers For Free
Most questions answered within 1 hours.