final exam 2

25
Test: Java Fundamentals Final Exam Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Top of Form Section 4 (Answer all questions in this section) 1. What is the output of the following lines of code? int j=6,k=4,m=12,result; result=j/m*k; System.out.println(result); Mark for Review (1) Points 2 0 (*) 48 24 Correct 2. Which line of Java code will assign the value of the square root of 11 to a variable named a? Mark for Review (1) Points double a=11^(1/2); double a=sqrt(11); int a=Math.sqrt(11); double a=Math.sqrt*11; double a=Math.sqrt(11); (*) Correct 3. A _______________ is used to organize Java related files. Mark for Review (1) Points Project Workspace

Upload: alexandra-ioana-trinca

Post on 07-Nov-2015

237 views

Category:

Documents


9 download

DESCRIPTION

gfhf

TRANSCRIPT

Test: Java Fundamentals Final Exam

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

Top of Form

Section 4

(Answer all questions in this section)

1.What is the output of the following lines of code?

int j=6,k=4,m=12,result;result=j/m*k;System.out.println(result);Mark for Review(1) Points

2

0 (*)

48

24

Correct

2.Which line of Java code will assign the value of the square root of 11 to a variable named a?Mark for Review(1) Points

double a=11^(1/2);

double a=sqrt(11);

int a=Math.sqrt(11);

double a=Math.sqrt*11;

double a=Math.sqrt(11); (*)

Correct

3.A _______________ is used to organize Java related files.Mark for Review(1) Points

Project

Workspace

Package (*)

Collection

Correct

4.You need to _______________ Java code to generate a .class fileMark for Review(1) Points

Collect

Compile (*)

Package

Assemble

Correct

5.A workspace can not have more than one stored projects. True or false?Mark for Review(1) Points

True

False (*)

Correct

Bottom of Form

6.A perspective is described as:Mark for Review(1) Points

A combination of views and editors (*)

A combination of views and windows

A combination of editor tabs

None of the above

Correct

7.Multiple windows are used when more than one file is open in the edit area. True or False?Mark for Review(1) Points

True

False (*)

Correct

8.The String methods equals and compareTo perform similar functions and differ in their return type. True or false?Mark for Review(1) Points

True (*)

False

Correct

9.The following program prints "Not Equal":

True or false?Mark for Review(1) Points

True (*)

False

Incorrect. Refer to Section 4 Lesson 4.

10.What will the following code segment output?

String s="\\\n\"\n\\\n\"";System.out.println(s);Mark for Review(1) Points

\" \"

""\""\""

\"\" (*)

"\"\""

Correct11.The following program prints "Not Equal". True or false?

Mark for Review(1) Points

True

False (*)

Correct

12.Given the code

String s1 = "abcdef";String s2 = "abcdef";String s3 = new String(s1);

Which of the following would equate to false?Mark for Review(1) Points

s1 == s2

s1 = s2

s3 == s1 (*)

s1.equals(s2)

s3.equals(s1)

Correct

13.Which of the two diagrams below illustrate the general form of a Java program?

Mark for Review(1) Points

Example A

Example B (*)

Correct

14.Which of the following defines a driver class?Mark for Review(1) Points

Contains a main method and other static methods. (*)

Contains classes that define objects.

Contains a main method, a package, static methods, and classes that define objects.

None of the above.

Correct

Section 5

(Answer all questions in this section)

15.How would you use the ternary operator to rewrite this if statement?

if (balance < 500)= 5) ? 0 : 10;

fee = ( balance >= 500) ? 10 : 0;

fee = ( balance > 5) ? 10 : 0;

Correct16.This keyword is used to instruct specific code when the input for a switch statement that does not match any of the cases.Mark for Review(1) Points

Switch

Case

Break

Default (*)

None of the above

Correct

17.switch statements work on all input types including, but not limited to, int, char, and String. True or false?Mark for Review(1) Points

True

False (*)

Correct

18.All of the following are essential to initializing a for loop, except which one?Mark for Review(1) Points

Initializing the iterator(i).

Having a conditional statement.

Updating the counter.

Having an if statement. (*)

Correct

19.In a for loop the counter is not automatically incremented after each loop iteration. Code must be written to increment the counter. True or false?Mark for Review(1) Points

True (*)

False

Correct

20.Updating the input of a loop allows you to implement the code with the next element rather than repeating the code always with the same element. True or false?Mark for Review(1) Points

True (*)

False

CorrectSection 6

(Answer all questions in this section)

21.Of the options below, what is the fastest run-time?Mark for Review(1) Points

n

n^2

lg(n) (*)

n*lg(n)

Correct

22.Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value in the first position, and repeating these steps for the remainder of the list. True or false?Mark for Review(1) Points

True (*)

False

Correct

23.Why might a sequential search be inefficient?Mark for Review(1) Points

It utilizes the "divide and conquer" method, which makes the algorithm more error prone.

It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)

It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.

It is never inefficient.

Correct

24.Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches on arrays. True or false?Mark for Review(1) Points

True (*)

False

Correct

25.If an exception is thrown by a method, where can the catch for the exception be?Mark for Review(1) Points

There does not need to be a catch in this situation.

The catch must be in the method that threw the exception.

The catch can be in the method that threw the exception or in any other method that called the method that threw the exception. (*)

The catch must be immediately after the throw.

Incorrect. Refer to Section 6 Lesson 3.26.Which of the following statements add all of the elements of the one dimensional array prices, and then prints the sum to the screen?Mark for Review(1) Points

int total = 0;for(int i = 0; itotal+=prices[i];

int total = 0;for(int i = 0; itotal+=prices[i];System.out.println(total); (*)

int total = 0;for(int i = 1; itotal = total+prices[i];System.out.println(prices);

int total = 0;for(int i = 0; itotal+=prices[i];System.out.println(prices);

Correct

27.The following array declaration is valid. True or false?

int[] y = new int[5];Mark for Review(1) Points

True (*)

False

Correct

28.What is the output of the following segment of code?

Mark for Review(1) Points

321111

11 (*)

111

1111

This code doesn't compile.

Correct

29.What is the output of the following segment of code if the command line arguments are "a b c d e f"?

Mark for Review(1) Points

1

3

5

6 (*)

This code doesn't compile.

Correct

Section 7

(Answer all questions in this section)

30.Static classes can't return instances of the parent class when the parent class uses a private constructor. True or false?Mark for Review(1) Points

True

False (*)

Incorrect. Refer to Section 7 Lesson 3.Section 7

(Answer all questions in this section)

31.There is only one copy a static class variable in the JVM. True or false?Mark for Review(1) Points

True (*)

False

Correct

32.A linear recursive method directly calls how many copies of itself in the recursive case?Mark for Review(1) Points

0

1 (*)

2 or more

Correct

33.Where should the constructor for a superclass be called?Mark for Review(1) Points

Anywhere inside the subclass.

Inside the main method of the subclass.

The last line in the constructor of the subclass.

The first line of the constructor in the subclass. (*)

The super constructor does not need to be called inside the subclass.

Correct

34.Which of the following correctly describes the use of the keyword super?Mark for Review(1) Points

A keyword that restricts access to only inside the same class.

A keyword that allows subclasses to access methods, data, and constructors from their parent class. (*)

A keyword that signals the end of a program.

A keyword that allows access from anywhere.

Correct

35.What is the Java Applet?Mark for Review(1) Points

(Choose all correct answers)

It is the virtual machine that translates Java code into a representation that the computer can understand.

A web-based Java program that is embedded into a web browser. (*)

A graphic visual included in Java. (*)

There is no such thing as a Java Applet.

Incorrect. Refer to Section 7 Lesson 4.36.What is encapsulation?Mark for Review(1) Points

A keyword that allows or restricts access to data and methods.

A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications.

A structure that categorizes and organizes relationships among ideas, concepts of things with the most general at the top and the most specific at the bottom.

A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods. (*)

Correct

37.Which segment of code correctly defines a method that contains two objects of class Tree as parameters?Mark for Review(1) Points

void bloom(Tree pine, Tree oak) {//code here }; (*)

Tree bloom (pine, oak) {//code here };

void bloom, Tree pine, Tree oak {//code here };

None of the above, objects cannot be passed as parameters.

Correct

38.Which of the following correctly defines overloading?Mark for Review(1) Points

Having more than one constructor with the same name but different arguments. (*)

Having more than one constructor with different names and the same arguments.

A variable argument method that returns an array.

A type of access specifier that only allows access from inside the same class.

Correct

39.Which of the following are access modifiers?Mark for Review(1) Points

(Choose all correct answers)

protected (*)

public (*)

secured

default (no access modifier) (*)

private (*)

Correct

40.It is possible to overload a method that is not a constructor. True or False?Mark for Review(1) Points

True (*)

False

Correct41.Choose the correct implementation of a public access modifier for the method divide.Mark for Review(1) Points

divide(int a, int b, public) {return a/b;}

public divide(int a, int b) {return a/b;} (*)

divide(int a, int b) {public return a/b;}

divide(public int a, public int b) {return a/b;}

Correct

42.Abstract classes can be instantiated. True or false?Mark for Review(1) Points

True

False (*)

Correct

43.Which of the following can be declared final?Mark for Review(1) Points

Classes

Methods

Local variables

Method parameters

All of the above (*)

Correct

44.What is Polymorphism?Mark for Review(1) Points

A way of redefining methods with the same return type and parameters.

A way to create multiple methods with the same name but different parameters.

A class that cannot be initiated.

The concept that a variable or reference can hold multiple types of objects. (*)

Correct

45.Which of the following creates a method that returns a boolean value?Mark for Review(1) Points

(*)

None of the above.

Correct46.What value will return for j when the setValue method is called?

Mark for Review(1) Points

31

32

10

11 (*)

Correct

47.If the return type from a method is boolean then 2.5 is a valid return value. True or false?Mark for Review(1) Points

True

False (*)

Correct

48.The constructor method must always have at least one parameter. True or false?Mark for Review(1) Points

True

False (*)

Correct

49.Which of the following creates an instance of the class below?

Mark for Review(1) Points

ThisClass t=new ThisClass();

ThisClass t;

ThisClass t=new ThisClass(3,4);

ThisClass t=new ThisClass(5); (*)

Correct

50.What is wrong with the following class declaration?

class Account{ ;private int number;private String name;;public Account;}Mark for Review(1) Points

Classes cannot include strings.

Classes cannot include mixed data types.

The constructor method has no definition. (*)

There is nothing wrong.

Correct_1463332059.unknown

_1463332091.unknown

_1463332107.unknown

_1463332115.unknown

_1463332119.unknown

_1463332121.unknown

_1463332122.unknown

_1463332120.unknown

_1463332117.unknown

_1463332118.unknown

_1463332116.unknown

_1463332111.unknown

_1463332113.unknown

_1463332114.unknown

_1463332112.unknown

_1463332109.unknown

_1463332110.unknown

_1463332108.unknown

_1463332099.unknown

_1463332103.unknown

_1463332105.unknown

_1463332106.unknown

_1463332104.unknown

_1463332101.unknown

_1463332102.unknown

_1463332100.unknown

_1463332095.unknown

_1463332097.unknown

_1463332098.unknown

_1463332096.unknown

_1463332093.unknown

_1463332094.unknown

_1463332092.unknown

_1463332075.unknown

_1463332083.unknown

_1463332087.unknown

_1463332089.unknown

_1463332090.unknown

_1463332088.unknown

_1463332085.unknown

_1463332086.unknown

_1463332084.unknown

_1463332079.unknown

_1463332081.unknown

_1463332082.unknown

_1463332080.unknown

_1463332077.unknown

_1463332078.unknown

_1463332076.unknown

_1463332067.unknown

_1463332071.unknown

_1463332073.unknown

_1463332074.unknown

_1463332072.unknown

_1463332069.unknown

_1463332070.unknown

_1463332068.unknown

_1463332063.unknown

_1463332065.unknown

_1463332066.unknown

_1463332064.unknown

_1463332061.unknown

_1463332062.unknown

_1463332060.unknown

_1463331995.unknown

_1463332027.unknown

_1463332043.unknown

_1463332051.unknown

_1463332055.unknown

_1463332057.unknown

_1463332058.unknown

_1463332056.unknown

_1463332053.unknown

_1463332054.unknown

_1463332052.unknown

_1463332047.unknown

_1463332049.unknown

_1463332050.unknown

_1463332048.unknown

_1463332045.unknown

_1463332046.unknown

_1463332044.unknown

_1463332035.unknown

_1463332039.unknown

_1463332041.unknown

_1463332042.unknown

_1463332040.unknown

_1463332037.unknown

_1463332038.unknown

_1463332036.unknown

_1463332031.unknown

_1463332033.unknown

_1463332034.unknown

_1463332032.unknown

_1463332029.unknown

_1463332030.unknown

_1463332028.unknown

_1463332011.unknown

_1463332019.unknown

_1463332023.unknown

_1463332025.unknown

_1463332026.unknown

_1463332024.unknown

_1463332021.unknown

_1463332022.unknown

_1463332020.unknown

_1463332015.unknown

_1463332017.unknown

_1463332018.unknown

_1463332016.unknown

_1463332013.unknown

_1463332014.unknown

_1463332012.unknown

_1463332003.unknown

_1463332007.unknown

_1463332009.unknown

_1463332010.unknown

_1463332008.unknown

_1463332005.unknown

_1463332006.unknown

_1463332004.unknown

_1463331999.unknown

_1463332001.unknown

_1463332002.unknown

_1463332000.unknown

_1463331997.unknown

_1463331998.unknown

_1463331996.unknown

_1463331963.unknown

_1463331979.unknown

_1463331987.unknown

_1463331991.unknown

_1463331993.unknown

_1463331994.unknown

_1463331992.unknown

_1463331989.unknown

_1463331990.unknown

_1463331988.unknown

_1463331983.unknown

_1463331985.unknown

_1463331986.unknown

_1463331984.unknown

_1463331981.unknown

_1463331982.unknown

_1463331980.unknown

_1463331971.unknown

_1463331975.unknown

_1463331977.unknown

_1463331978.unknown

_1463331976.unknown

_1463331973.unknown

_1463331974.unknown

_1463331972.unknown

_1463331967.unknown

_1463331969.unknown

_1463331970.unknown

_1463331968.unknown

_1463331965.unknown

_1463331966.unknown

_1463331964.unknown

_1463331947.unknown

_1463331955.unknown

_1463331959.unknown

_1463331961.unknown

_1463331962.unknown

_1463331960.unknown

_1463331957.unknown

_1463331958.unknown

_1463331956.unknown

_1463331951.unknown

_1463331953.unknown

_1463331954.unknown

_1463331952.unknown

_1463331949.unknown

_1463331950.unknown

_1463331948.unknown

_1463331931.unknown

_1463331939.unknown

_1463331943.unknown

_1463331945.unknown

_1463331946.unknown

_1463331944.unknown

_1463331941.unknown

_1463331942.unknown

_1463331940.unknown

_1463331935.unknown

_1463331937.unknown

_1463331938.unknown

_1463331936.unknown

_1463331933.unknown

_1463331934.unknown

_1463331932.unknown

_1463331923.unknown

_1463331927.unknown

_1463331929.unknown

_1463331930.unknown

_1463331928.unknown

_1463331925.unknown

_1463331926.unknown

_1463331924.unknown

_1463331915.unknown

_1463331919.unknown

_1463331921.unknown

_1463331922.unknown

_1463331920.unknown

_1463331917.unknown

_1463331918.unknown

_1463331916.unknown

_1463331911.unknown

_1463331913.unknown

_1463331914.unknown

_1463331912.unknown

_1463331907.unknown

_1463331909.unknown

_1463331910.unknown

_1463331908.unknown

_1463331905.unknown

_1463331906.unknown

_1463331903.unknown

_1463331904.unknown

_1463331901.unknown

_1463331902.unknown

_1463331900.unknown