1. In the Quiz class, the foo method has the following API: public char foo( int
ID: 3861456 • Letter: 1
Question
1. In the Quiz class, the foo method has the following API:
public char foo( int i, String s, double c )
Which method call(s) could be correct assuming a is an int and y is an int and each statement is complete?
char c = Quiz.foo( 1, “Hmmm!”, 0.1 );
All of the above
2.
What is the output of the following code sequence?
a space is printed
W
Hello
o
3.
What is the output of the following code sequence?
Read a book
Go sailing
none of the above
4.
What is the output of the following code sequence?
D or Lower
Done
5.
What is the output of the following code sequence?
Season is Fall
Season is Winter
Season is Spring
End of Seasons
Season is Summer
Season is Fall
Season is Winter
Season is Spring
Season is Summer
6.
Given the following code declaring and initializing three boolean variables x, y and z with respective values true, true, and false, does the following expression evaluate to true or false?
boolean x = true;
boolean y = true;
boolean z = false;
Expression: ((x || y) && !z)
True
False
7.
Given the following code declaring and initializing three boolean variables x, y and z with respective values true, true, and false, does the following expression evaluate to true or false?
boolean x = true;
boolean y = true;
boolean z = false;
Expression: ((x && z) || y)
True
False
8.
Given the following code declaring and initializing two int variables x and y with respective values 19 and 17, does the value of the expression evaluate to true or false.
int x = 19;
int y = 17;
Expression: x > y || !( x>y )
True
False
9.
Given the following code declaring and initializing two int variables x and y with respective values 19 and 17, does the value of the expression evaluate to true or false.
int x = 19;
int y = 17;
Expression: y >= 17
True
False
10.
Given the following code declaring and initializing two int variables x and y with respective values 19 and 17, does the value of the expression evaluate to true or false.
int x = 19;
int y = 17;
Expression: ( x - 2 == y ) && ( y>x )
True
False
11.
Given two boolean expressions a and b, are the following expressions equivalent?
!( a && b )
!a || !b
True
False
12.What are the values of i and product after this code sequence is executed?
i is 9
product is 336
i is 8
product is 42
i is 8
product is 14
d. i is 10
product is 3024
13.
What are the values of i and sum after this code sequence is executed?
int i = 0;
int sum = 0;
for ( i = 0; i < 40; i++)
{
if ( i % 10 = = 0)
sum += i ;
}
i is 40
sum is 60
i is 39
sum is 40
i is 40
sum is 40
i is 39
sum is 60
14.
If you want to execute a loop body at least once, what type of looping structure would you use?
for loop
while loop
do/while loop
none of the above
15.
What is the output of this code sequence? (The user successively enters 3, 5, and -1.)
System.out.print( “Enter an int > “ );
int i = scan.nextInt( );
while ( i != -1)
{
System.out.print( “Enter an int > “ );
i = scan.nextInt( );
System.out.println( “Hello” );
}
Enter an int > 3
Hello
Enter an int > 5
Hello
Enter an int > -1
Hello
Enter an int > 3
Hello
Enter an int > 5
Hello
Enter an int > -1
Enter an int > 3
Enter an int > 5
Hello
Enter an int > -1
Hello
none of the above
True or false. You can simulate a for loop with a while loop?
True
False
16.
What are the values of i and sum after this code sequence is executed?
int i = 0;
int sum = 0;
while ( i < 7 )
{
sum += i;
++i;
}
i is 6
sum is 21
i is 8
sum 21
i is 7
sum is 21
i is 6
sum is 15
17.
In the Quiz class, the foo method has the following API:
public static double foo( float f )
What can you say about the method foo?
it is an instance method
it is a class field
it is a class method
it is an instance variable
18.
To instantiate an object instance of class SimpleDate assuming an overloaded SimpleDate class constructor requiring 3 int parameters exists, which statement(s) could be used to instantiate an object of type SimpleDate?
SimpleDate s1 = SimpleDate(1, 2, 3);
SimpleDate s2 = new SimpleDate(1, 2, 3);
SimpleDate s3 = new SimpleDate();
d. b and c
19.
What is the value of i and how many times will the word “Hello” have printed after this code sequence is executed?
int i = 0;
for( i = 0; i < =2; i++)
{
System.out.println( "Hello");
}
i is 2
Hello prints 2 times
i is 3
Hello prints 3 times
i is 2
Hello prints 3 times
i is 3
Hello prints 2 times
20.
What is output after the following code sequence is executed?
piF and piD are equal
piF and piD are not equal
piF and piD are equal
piF and piD are considered equal
piF and piD are not equal
piF and piD are not equal
piF and piD are not equal
piF and piD are considered equal
Quiz q = new Quiz();
a = Quiz.foo( y, “Maybe?”, 1.0 );b.
char c = Quiz.foo( 1, “Hmmm!”, 0.1 );
c.Quiz q = new Quiz();
System.out.println( q.foo( y, “You think.”, 2.0));d.
All of the above
Explanation / Answer
Q1. option B and C are Correct.
Option A is incorrect because return type is not matched.
_______________________________________________________
Q2.option A is correct. It prints blank space.
________________________________________
Q3.Option A , Read a book is printed
_______________________________________
Q4.option D.
it prints,D or lower
Done
______________________________
Q5.Option B
it prints"End of Seasons"
__________________________________________
Q6. Answer is True
because x or y is true ,
true && !false =true
_________________________________________
Q7. True
because x and z is false
false or true is true
_____________________________________________________________
Q8.Answer is true
Expression: x > y || !( x>y )
x>y is true
!(x>y)is false
true or false is true
__________________________________
9. True
y=17.
__________________________________
10.Answer is false because y>x is false.
____________________________________
11.True
Give expressions are equivalent
__________________________________________
12.option D
i=10 , product=3024
________________________________
13. option A
i=40, sum=60
_____________________________
14.
option C,
We have use do-while loop to execute loop atleast one time
____________________________
15.The output given in option C is correct.
_______________________________
16.option C is correct
i is 7
sum is 21
________________________________________
17.option C
It is a class method , because it is static
___________________________________
18.option D
both b and c are correct methods of instantiation
_______------------
19.option B
i=3, hello prints 3 times.
___________________________
20.optionD
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.