Sie sind auf Seite 1von 21

Which

statement Mark for Review


is a
(1) Points
syntactically
correct way
to declare
an Array?

int i[1] id;

int id[]; (*)

int i[1];

int[5] id={1,2,3,4,5};

incorrect. Refer to Section 1 Lesson 1.

12. When you instantiate a subclass, the superclass constructor will be also
invoked. True or False? Mark for Review
(1) Points

True (*)

False

incorrect. Refer to Section 1 Lesson 1.

13. What is the output from the following code snippet?


Mark for Review
boolean status=false;
(1) Points
int i=1;
if( (++i>1) && (status=true))
i++;
if( (++i>3) || (status=false))
i++;
System.out .println (i);

5 (*)

Correct

14. Which of the following operators are logic operators?(Choose Two)


Mark for Review
(1) Points

(Choose all correct answers)


<=

&& (*)

! (*)

>

Correct

15. Which combination of the following overload the Student


constructor?(Choose Two) Mark for Review
(1) Points

(Choose all correct answers)

protected int Student(){}

public Student(int x,int y){} (*)

public void Student(int x, int y){}

public Object Student(int x,int y){}

public Student(){} (*)

Correct

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)

6. What do Arrays and ArrayLists have in common?


I. They both store data. Mark for Review
II. They can both be traversed in loops.
(1) Points
III. They both can be dynamically re-sized during execution of a program.

I only

II only

I and II only (*)

I, II and III only

None of these

Correct
7. Examine the following code snippet. What is this an example of?
Mark for Review
public class Car extends Vehicle {
(1) Points
public Car() {
...
}
}

Encapsulation

Polymorphism

Inheritance (*)

Comments

Incorrect. Refer to Section 1 Lesson 2.

8. Examine the following Classes:


Student and TestStudent Mark for Review
What is the output from the println statement in TestStudent?
(1) Points
public class Student {
private int studentId = 0;

public Student(){
studentId++;
}
public static int getStudentId(){
return studentId;
}
}

public class TestStudent {


public static void main(String[] args) {
Student s1 = new Student();
Student s2 = new Student();
Student s3 = new Student();
System.out.println(Student.getStudentId());
}
}

TestStudent will throw an exception

No output. Compilation of TestStudent fails (*)

incorrect. Refer to Section 1 Lesson 1.

9. The following code can be compiled, True/False?


byte b = 1 + 1; Mark for Review
(1) Points

True (*)
False

Correct

10. What is the output from the following code snippet?


for (int i = 0; i < 10; i++) { Mark for Review
if (i == 3) {
(1) Points
break;
}
System.out.print(i);

The code will compile and print "123"

The code will compile and print "012" (*)

The code will compile and print "0123"

The code does not compile.

incorrect. Refer to Section 1 Lesson 1.

Previous Page 2 of 3 Next Summary

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. Which statement is true for the class java.util.ArrayList?


Mark for Review
(1) Points

The elements in the collection are ordered. (*)

The elements in the collection are immutable.

The elements in the collection are synchronized.

The elements in the collection are accessed using key.

Correct

2. Arrays have built-in operations including add, clear, contains, get and remove. True
or false? Mark for Review
(0) Points
True

False (*)

Correct

3. Which of the following statements is false?


Mark for Review
(1) Points

In an Array you need to know the length and the current number of elements
stored.
An ArrayList can store multiple object types.

An ArrayList has a fixed length. (*)

An ArrayList can grow and shrink dynamically as required.

Incorrect. Refer to Section 1 Lesson 2.

4. Why is it helpful for new programmers to read pre-written code?(Choose Two)


Mark for Review
(1) Points

(Choose all correct answers)

Learn new programming techniques. (*)

It is not helpful to read code written by other programmers.

Meet new programmers.

Understand code written by other programmers. (*)

Incorrect. Refer to Section 1 Lesson 2.

5. Which of the following are important to your survival as a programmer?


Mark for Review
(1) Points

Being good at reading code.

Looking for opportunities to read code.

Being good at testing.

All of these. (*)

Correct

Nex Summa
Page 1 of 3
t ry
Test: Section 2 Quiz 1 - L1-L3

Review your answers, feedback, and question scores below. An asterisk (*) indicates a
correct answer.

Section 2 - Quiz 1 L1-L3


(Answer all questions in this section)

1. < ? extends Animal > is an example of a bounded generic


wildcard. Mark for Review
True or False?
(1) Points

True (*)

False

Correct

2. Examine the code below. Which statement about this code


is true? Mark for Review
(1) Points
1.class Shape { }
2.class Circle extends Shape { }
3.class Rectangle extends Shape { }

4.class Node { }

5.public class Test{

6.public static void main(String[] args){

7.Node nc = new Node<>();


8.Node ns = nc;
}
}

The code compiles.

An error at line 4 causes compilation to fail.

An error at line 7 causes compilation to fail.

An error at line 8 causes compilation to fail. (*)

Incorrect. Refer to Section 2 Lesson 3.

3. An example of an upper bounded wildcard is.


Mark for Review
(1) Points

ArrayList<? extends Animal> (*)

ArrayList<?>
ArrayList<? super Animal>

ArrayList<T>

Correct

4. What is the correct definition of Enumeration (or enum)?


Mark for Review
(1) Points

A bounded generic class

A list of elements that is dynamically stored.

A keyword that specifies a class whose objects are


defined inside the class. (*)
Code that initializes an ArrayList

Incorrect. Refer to Section 2 Lesson 3.

5. Assuming that there is a class Gum, what is the result from


the following code snippet? Mark for Review
(1) Points
public static void main(String[] args) {
List<Gum> list1 = new ArrayList<Gum>();
list1.add(new Gum());
List list2 = list1;
list2.add(new Integer(9));
System.out.println(list2.size());
}

2 (*)

The code will not compile.

an exception will be thrown at runtime

Incorrect. Refer to Section 2 Lesson 3.

Page 1 of 3 Next Summary

Test: Section 2 Quiz 1 - L1-L3

Review your answers, feedback, and question scores below. An asterisk (*) indicates a
correct answer.

Section 2 - Quiz 1 L1-L3


(Answer all questions in this section)
6. An abstract class can implement its methods.
True or false? Mark for Review
(1) Points

True (*)

False

Incorrect. Refer to Section 2 Lesson 2.

7. The instanceof operator is a boolean comparison operator.


True or false? Mark for Review
(1) Points

True (*)

False

Correct

8. The instanceof operator enables to discover the type of


object it was invoked upon. Mark for Review
True or false?
(1) Points

True (*)

False

Correct

9. The instanceof operator can find subclass objects when


they are passed to method which declare a superclass type Mark for Review
parameter.
(1) Points
True or false?

True (*)

False

Incorrect. Refer to Section 2 Lesson 2.

10. Which method will force a subclass to implement it?


Mark for Review
(1) Points

Abstract public void act(); (*)

Static void act(String name) {}

Public native double act();


Public double act();

Protected void act(String name){}

Incorrect. Refer to Section 2 Lesson 2.

Previous Page 2 of 3 Next Summary

Test: Section 2 Quiz 1 - L1-L3

Review your answers, feedback, and question scores below. An asterisk (*) indicates a
correct answer.

Section 2 - Quiz 1 L1-L3


(Answer all questions in this section)

11. A method with default access can be subclassed.


True or false? Mark for Review
(1) Points

True

False (*)

Correct

12. All classes can by subclassed.


Mark for Review
(1) Points

True

False (*)

Correct

13. Immutable classes do allow instance variables to be


changed by overriding methods. Mark for Review
True or false?
(1) Points

True

False (*)

Incorrect. Refer to Section 2 Lesson 1.


14. An interfaces can declare public constants.
True or False? Mark for Review
(1) Points

True (*)

False

Correct

15. Which two statements are equivalent to line 2?


(Choose Two) 1. public interface Account{ Mark for Review
2. int accountID=100;
(1) Points
3. }

(Choose all correct answers)

Abstract int accountID=100;

Final int accountID=100; (*)

private int accountID=100;

protected int accountID=100;

static int accountID=100; (*)

Incorrect. Refer to Section 2 Lesson 1.

Previous Page 3 of 3 Summary

Test: Section 2 Quiz 2 - L4-L6

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 2 - Quiz 2 L4-L6


(Answer all questions in this section)

1. Which of these could be a set? Why?


Mark for Review
(1) Points

{1, 1, 2, 22, 305, 26} because a set may contain duplicates and all its
elements are of the same type.
{"Apple", 1, "Carrot", 2} because it records the index of the elements with
following integers.
{1, 2, 5, 178, 259} because it contains no duplicates and all its elements are
of the same type. (*)
All of the above are sets because they are collections that can be made to fit
any of the choices.

Correct

2. Which of the following correctly adds "Cabbage" to the ArrayList vegetables?


Mark for Review
(1) Points

vegetables.add("Cabbage"); (*)

vegetables += "Cabbage";

vegetables.get("Cabbage");

vegetables[0] = "Cabbage";

Correct

3. What is a set?
Mark for Review
(1) Points

A collection of elements that does not contain duplicates. (*)

A collection of elements that contains duplicates.

A keyword in Java that initializes an ArrayList.

Something that enables you to create a generic class without specifying a


type between angle brackets <>.

Correct

4. ArrayList and Arrays both require you to define their size before use.
True or false? Mark for Review
(1) Points

True

False (*)

Correct

5. A LinkedList is a list of elements that is dynamically stored.


True or false? Mark for Review
(1) Points

True (*)

False
Correct

Page 1 of 3 Next Summary

Test: Section 3 Quiz 1 - L1-L3

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 3 - Quiz 1 L1-L3


(Answer all questions in this section)

1. Which of the following are true about parsing a String?(Choose Three)


Mark for Review
(1) Points

(Choose all correct answers)

It is possible to use the String.split() method to parse a string. (*)

It is a way of dividing a string into a set of sub-strings. (*)

It is not possible to parse a string using regular expressions.

It is possible to use a for loop to parse a string. (*)

Correct

2. Identify the method, of those listed below, that is not available to both
StringBuilders and Strings? Mark for Review
(1) Points

length()

charAt(int index)

indexOf(String str)

delete(int start, int end) (*)

Correct

3. Which of the following correctly defines a StringBuilder?


Mark for Review
(1) Points

A method that adds characters to a string.

A class inside the java.util.regex package.


A class that represents a string-like object. (*)

There is no such thing as a StringBuilder in Java.

Correct

4. What class is the split() method a member of?


Mark for Review
(1) Points

Array

String (*)

StringBuilder

Parse

Correct

5. Matcher has a find method that checks if the specified pattern exists as a sub-string
of the string being matched. Mark for Review
True or false?
(1) Points

True (*)

False

Correct

Page 1 of 3 Next Summary

Test: Section 3 Quiz 1 - L1-L3

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 3 - Quiz 1 L1-L3


(Answer all questions in this section)

6. Which of the following correctly defines a repetition operator?


Mark for Review
(1) Points

A symbol that represents any character in regular expressions.

A method that returns the number of occurrences of the specified character.

symbol in regular expressions that indicates the number of occurrences a


specified character appears in a matching string. (*)
None of the above.

Correct

7. The following code correctly initializes a pattern with the regular expression "[0-
9]{2}/[0-9]{2}/[0-9]{2}". Mark for Review
(1) Points
Pattern dateP = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{2}");

True or false?

True (*)

False

Correct

8. What is the correct explanation of when this code will return true?
Mark for Review
return str.matches(".*[0-9]{6}.*");
(1) Points

Any time that str contains two dots.

Any time that str contains a sequence of 6 digits. (*)

Any time that str has between zero and nine characters followed by a 6.

Any time str contains a 6.

Always.

Incorrect. Refer to Section 3 Lesson 2.

9. Square brackets are a representation for any character in regular expressions "[
]". Mark for Review
True or false?
(1) Points

True

False (*)

Correct

10. Consider designing a program that organizes your contacts alphabetically by last
name, then by first name. Oddly, all of your contacts' first and last names are Mark for Review
exactly five letters long.
(1) Points
Which of the following segments of code establishes a Pattern namePattern with a
group for the first name and a group for the last name considering that the string
contactsName is always in the format lastName_firstName?

Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)

Pattern namePattern = Pattern.compile("first_last");


Pattern namePattern = new Pattern(last{5},first{5});

Pattern namePattern = new Pattern();

None of the above.

Correct

Previous Page 2 of 3 Next Summary

Test: Section 3 Quiz 1 - L1-L3

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 3 - Quiz 1 L1-L3


(Answer all questions in this section)

11. Which of the following correctly defines Matcher?


Mark for Review
(1) Points

A method of dividing a string into a set of sub-strings.

A class in the java.util.regex package that stores the format of a regular


expression.
A class in the java.util.regex package that stores the matches between a
pattern and a string. (*)
A regular expression symbol that represents any character.

Correct

12. Which two statements can create an instance of an array? (Choose Two)
Mark for Review
(1) Points

(Choose all correct answers)

Object oa = new double[5]; (*)

int[] ia = new int [5]; (*)

double da = new double [5];

char[] ca = "java";

int ia[][] = (1,2,3) (4,5,6);

Incorrect. Refer to Section 3 Lesson 3.


13. The base case condition can work with a constant or variable.
True or false? Mark for Review
(1) Points

True (*)

False

Correct

14. A non-linear recursive method is less expensive than a linear recursive method.
True or false? Mark for Review
(1) Points

True

False (*)

Correct

15. Consider the following recursive method recur(x, y). What is the value of recur(4,
3)? Mark for Review
(1) Points
public static int recur(int x, int y) {
if (x == 0) {
return y;
}
return recur(x - 1, x + y);
}

13 (*)

10

12

Correct

Previous Page 3 of 3 Summary

Test: Section 3 Quiz 2 - L4-L6

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 3 - Quiz 2 L4-L6
(Answer all questions in this section)

1. The Files class provides a instance method that creates a new BufferedReader.
True or false? Mark for Review
(1) Points

True (*)

False

Correct

2. An ObjectInputStream lets you read a serialized object.


True or false? Mark for Review
(1) Points

True (*)

False

Incorrect. Refer to Section 3 Lesson 5.

3. The Paths class provides a static get() method to find a valid Path.
True or false? Mark for Review
(1) Points

True (*)

False

Correct

4. Which statement determine that "java" is a directory?


Mark for Review
(1) Points

Boolean isDir=Directory.exists ("java");

Boolean isDir=(new File("java")).isDir();

Boolean isDir=(new File("java")).isDirectory();

Boolean isDir=(new Directory("java")).exists(); (*)

Incorrect. Refer to Section 3 Lesson 5.

5. Which statements are true when you compile and run this code.(Choose Two)
Mark for Review
1. public class Test{
(1) Points
2. public static String sayHello(String name) throws Exception{
3. if(name == null) throw new Exception();
4. return "Hello " + name;
5. }
6. public static void main(String[] args){
7. sayHello("Java");
8. }
9. }

(Choose all correct answers)

can not create Exception object in the Test Class.

The class Test compiles if line 7 is enclosed in a try-catch block. try{


sayHello("Java"); }catch(Exception e){} (*)
Compilation succeeds

The class Test compiles if line 6 contains a throws statement. public static
void main(String[] args) throws Exception{ (*)

Incorrect. Refer to Section 3 Lesson 6.

Page 1 of 3 Next Summary

Test: Section 3 Quiz 2 - L4-L6

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 3 - Quiz 2 L4-L6


(Answer all questions in this section)

6. What is exception handling?


Mark for Review
(1) Points

A consistent way of handling various errors. (*)

When a file fails to open.

If your program exits before you expect it to.

An error that occurs against the flow of your program.

Correct

7. Methods can not throw exceptions.


True or false? Mark for Review
(1) Points

True

False (*)
Correct

8. Multiple exceptions can be caught in one catch statement.


True or false? Mark for Review
(1) Points

True (*)

False

Correct

9. Which three types of objects can be thrown using a throw statement? (Choose
Three) Mark for Review
(1) Points

(Choose all correct answers)

Throwable (*)

Error (*)

Event

Exception (*)

Object

Incorrect. Refer to Section 3 Lesson 6.

10. What is the definition of a logic error?


Mark for Review
(1) Points

Wrong syntax that will be caught at compile time.

Bugs in code that make your program run different than expected (*)

Computer malfunction that makes your code run incorrectly.

Something that causes your computer to crash.

Incorrect. Refer to Section 3 Lesson 6.

Previous Page 2 of 3 Next Summary

Test: Section 3 Quiz 2 - L4-L6

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 3 - Quiz 2 L4-L6
(Answer all questions in this section)

11. What is the result from creating the following try-catch block?
Mark for Review
1.try {
(1) Points
2.} catch (Exception e) {

3.} catch (ArithmeticException a) {

4.}

The code compiles

Compile fails at Line 1

Compile fails at Line 2

Compile fails at Line 3 (*)

Incorrect. Refer to Section 3 Lesson 6.

12. The Files class can perform which of the following functions?
Mark for Review
(1) Points

Navigates the file system

Creates files (*)

Works across disk volumes

Works with absolute paths

Works with relative paths

Correct

13. The new Paths class lets you resolve .. (double dot) path notation.
True or false? Mark for Review
(1) Points

True (*)

False

Correct

14. Which of the following is an absolute Windows path?


Mark for Review
(1) Points
C:\Users\UserName\data (*)

/home/user/username

\Users\UserName\data

data

Correct

15. Java 7 requires you create an instance of java.nio.file.File class.


True or false? Mark for Review
(1) Points

True

False (*)

Correct

Previous Page 3 of 3 Summary

Das könnte Ihnen auch gefallen