Test: Section 1 Quiz
Test: Section 1 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 1 Quiz
(Answer all questions in this section)
1. What is the final value of result from the following code snippet?
int i = 1; Mark for Review
int [] id = new int [3]; (1) Points
int result = id [i];
result = result + i;
The code will compile, result has the value of 2
The code will compile, result has the value of 1 (*)
The code will not compile, result has the value of 2
The code will compile, result has the value of 0
An exception is thrown.
Correct
2. What is the output from the following code snippet?
Mark for Review
int[] myarray={1,2,3,4,5}; (1) Points
int sum=0;
for (int x : myarray)
sum+=x;
System.out.println("sum= " + sum);
20
15 (*)
10
The code will not compile.
Section 1 Quiz
(Answer all questions in this section)
6. What is the output from the following code?
Mark for Review
int x=5; (1) Points
if (x>6)
System. out. println("x>l");
else if (x>=5)
System. out .println("x>=5");
else if (x<10)
System. out. println("x<10");
else
System.out.println("none of the above");
x<10
None of these answers are correct
x>6
x>=5 (*)
Section 1 Quiz
(Answer all questions in this section)
11. Which of the following is not a good technique to follow when reading code written by
others? Mark for Review
(1) Points
Find the author of the code and ask him how it works. (*)
Perform testing.
Learn the high level structure and starting point, and then figure out how it
branches.
Understand the constructs.
Build and run the code.
Correct
13. Which statement is true for the class java.util.ArrayList?
Mark for Review
(1) Points
The elements in the collection are synchronized.
The elements in the collection are ordered. (*)
The elements in the collection are immutable.
The elements in the collection are accessed using key.
Correct
15. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is
working correctly before it is combined with other components in the system. True or Mark for Review
false? (1) Points
True (*)
False
Correct
Section 1 Quiz
(Answer all questions in this section)
1. Which two statements prevent a method from being overriden? (Choose Two)
Mark for Review
(1) Points
(Choose all correct answers)
Final void act() {} (*)
Static void act() {}
Static final void act() {} (*)
Void final act() {}
Final abstract void act() {}
Correct
2. The following code can be compiled, True/False?
byte b = 1 + 1; Mark for Review
(1) Points
True (*)
False
True
False (*)
Correct
Section 1 Quiz
(Answer all questions in this section)
6. Class Object is the root of the Java class hierarchy. True or False?
Mark for Review
(1) Points
True (*)
False
Correct
7. Which of following statments are true when you create a object from class Object at
runtime as seen below. (Choose Three) Mark for Review
(1) Points
java.lang.Object obj = new java.lang.Object();
(Choose all correct answers)
Memory is allocated for a new object, if available. (*)
A new instance of class Object is created. (*)
Reference obj can be reassigned to any other type of object. (*)
This Object instance will not be created because you never defined class Object.
Correct
10. When an object is able to pass on its state and behaviors to its children, this is called:
Mark for Review
(1) Points
Polymorphism
Isolation
Encapsulation
Inheritance (*)
Section 1 Quiz
(Answer all questions in this section)
11. Unit testing can help you isolate problem quickly. True or False?
Mark for Review
(1) Points
True (*)
False
True (*)
False
Section 1 Quiz
(Answer all questions in this section)
1. Which ofthe following declarations are wrong?(Choose Three)
Mark for Review
(1) Points
(Choose all correct answers)
abstract final class Hello{} (*)
abstract private void act(){} (*)
protected private int id; (*)
public abstract class Student{}
Section 1 Quiz
(Answer all questions in this section)
6. Which of the following types are primitive data types? (Choose Two)
Mark for Review
(1) Points
(Choose all correct answers)
boolean (*)
String
double (*)
Integer
Correct
Section 1 Quiz
(Answer all questions in this section)
11. When an object is able to pass on its state and behaviors to its children, this is called:
Mark for Review
(1) Points
Polymorphism
Isolation
Inheritance (*)
Encapsulation
Correct
15. Which of the following statements about arrays and ArrayLists in Java are true?
I. An Array has a fixed length. Mark for Review
II. An Array can grow and shrink dynamically as required. (1) Points
III. An ArrayList can store multiple object types.
IV. In an ArrayList you need to know the length and the current number of elements
stored.
I and III only (*)
II and IV only
I, II, and III only
I, II, III and IV
None of these
Section 1 Quiz
(Answer all questions in this section)
1. Unit testing is the phase in software testing in which individual software modules are
combined and tested as a whole. True or false? Mark for Review
(1) Points
True
False (*)
Correct
2. Reading great code is just as important for a programmer as reading great books is for
a writer. True or false? Mark for Review
(1) Points
True (*)
False
Correct
4. In the relationship between two objects, the class that is being inherited from is called
the maxi-class. True or false? Mark for Review
(1) Points
True
False (*)
Correct
5. Unit testing can help you isolate problem quickly. True or False?
Mark for Review
(1) Points
False
True (*)
Correct
Section 1 Quiz
(Answer all questions in this section)
6. Which of the following is not a good technique to follow when reading code written by
others? Mark for Review
(1) Points
Understand the constructs.
Perform testing.
Find the author of the code and ask him how it works. (*)
Learn the high level structure and starting point, and then figure out how it
branches.
Build and run the code.
Correct
7. Which of the following statements about inheritance is false?
Mark for Review
(1) Points
A subclass inherits all the members (fields, methods, and nested classes) from its
superclass.
Inheritance allows you to reuse the fields and methods of the super class without
having to write them yourself.
Inheritance allows you to minimize the amount of duplicate code in an application
by sharing common code among several subclasses.
Through inheritance, a parent class is a more specialized form of the child class.
(*)
Correct
8. Which of following statments are true when you create a object from class Object at
runtime as seen below. (Choose Three) Mark for Review
(1) Points
java.lang.Object obj = new java.lang.Object();
(Choose all correct answers)
Reference obj can be reassigned to any other type of object. (*)
This Object instance will not be created because you never defined class Object.
A new instance of class Object is created. (*)
Memory is allocated for a new object, if available. (*)
correct
9. What is the output from the following code snippet?
String str1= "java"; Mark for Review
String str2=new String("java"); (1) Points
System.out.println( str1==str2 );
System.out.println( str1==str2.intern() );
The code does not compile.
The code will compile and print "true true"
The code will compile and print "true false"
The code will compile and print "false true" (*)
The code will compile and print "false false"
True
False (*)
Correct
Section 1 Quiz
(Answer all questions in this section)
11. Examine the following Classes:
Student and TestStudent Mark for Review
What is the output from the println statement in TestStudent? (1) Points
public Student(){
studentId++;
}
public static int getStudentId(){
return studentId;
}
}
Correct
12. Class Object is the root of the Java class hierarchy. True or False?
Mark for Review
(1) Points
True (*)
False
Correct
13. Which two statements are access modifier keywords in Java?(Choose Two)
Mark for Review
(1) Points
(Choose all correct answers)
public (*)
protected (*)
final
abstract