Question: Answer the Questions(Multiple Choice ): Question 11 What are the values of i and sum after this code sequence is executed? int i = 0;
Answer the Questions(Multiple Choice):
Question 11
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 ;
}
| a. | i is 40 sum is 60 | |
| b. | i is 41 sum is 60 | |
| c. | i is 40 sum is 100 | |
| d. | i is 41 sum is 100 |
2.5 points
Question 12
What is the output of the following code sequence:
double a = 16 / 5; System.out.println( a );
| a. | 2.6 | |
| b. | 3.2 | |
| c. | a | |
| d. | 3.0 |
2.5 points
Question 13
Given code:
public abstract class A{ } public class B extends A { }
The following code sequence would correctly create an object reference of class A holding an object reference for an object of class B:
A c; c = new B();
True
False
2.5 points
Question 14
Given the following code declaring and initializing two int variables x and y with respective values 7 and 9, answer question 14 indicating whether the value of the expression is true or false.
int x = 7; int y = 9;
Expression: ( y x == 0 || ( x + 2 ) != y)
True
False
2.5 points
Question 15
Class SimpleDate encapsulates integer instance variables month, day and year. Consider the following equals method in class SimpleDate:
public boolean equals( Object o ) { if ( !( d instanceof SimpleDate ) )
return false;
( Insert appropriate code from selections below)
if ( month == d1.month
&& day == d1.day && year == d1.year )
return true;
else
return false;
}
Which statement(s) could be used to complete the above method body code correctly?
| a. | SimpleDate d1; d1 = (SimpleDate)o; | |
| b. | SimpleDate d1 = o; | |
| c. | SimpleDate d1 = (SimpleDate)o; | |
| d. | Both a and c |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
