wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

MSTIP-CC102-FinalExam

Total questions: 90

Worksheet time: 2hrs 30mins

Name
Class
Date
1.

All Java programs begin execution in this method:

a)

start()

b)

main()

c)

runUntilHalt(int)

d)

main(String[])

2.

The Collections Framework is a group of Java components in the

a)

java.lang package

b)

com.java.util package

c)

java.structures package

d)

java.util package

e)

java.storage package

3.

Your custom package code space should take the following form:

a)

anything-i-want

b)

#$_3@&-*

c)

<org-category>.<org-name>.<project-name>

d)

<target-platform>.<year>.<month>

4.

To output data to the screen, we use a command called?

a)

Print.out.line

b)

System.out.print

c)

Print Screen

d)

Data.out.printline

5.

Select the properly formed comment:

a)

\* This is a valid comment *\

b)

/ This is a valid comment

c)

// This is a valid comment

d)

?* This is a valid comment *?

6.

Select the properly formed output line to generate the following output:

Hello World!

a)

System.out.print(Hello World!);

b)

System.out.println("Hello World!");

c)

System.out.print("Hello World);

d)

System.out.print("Hello World!")

7.

What is the output for the following statement:

System.out.print("1"+"1");

a)

11

b)

2

c)

Error Message

8.

Indicate the actual output of the statements below:

int thisYear = 2019;

System.out.println("The current year is "+thisYear);

a)

The current year is thisYear

b)

The current year is 2019

c)

No output; an error exists

d)

The current year is2019

9.

Which term below means violating a programming language's rules on how symbols can be combined to create a program?

a)

Logic Error

b)

Style Error

c)

Program Error

d)

Syntax Error

10.

Which provides runtime environment for java byte code to be executed?

a)

JDBC

b)

JVM

c)

JAVAC

d)

JAVA

11.

The ----------------- define only abstract method and final fields.

a)

classes

b)

package

c)

interface

d)

method

12.

the type ------------------- specifies a single precision value that uses 32 bits of storage

a)

byte

b)

short

c)

float

d)

double

13.

1. The --------- package contain classes for primitive type, string, math functions and thread.

a)

java.io

b)

java.lang

c)

java.util

d)

java.new

14.

which of the following method used to draw a square

a)

drawRect()

b)

drawLine()

c)

drawString()

d)

drawPolygon()

15.

What is the value of y after evaluation: x = 7; y = ++x * 3 - 2

a)

19

b)

20

c)

21

d)

22

16.

What is the value of y after evaluation: x = 7; y = ++x * 3 - 2

a)

19

b)

20

c)

21

d)

22

17.

What type of values represent the outcome of the relational and logical operators?

a)

constant values

b)

Boolean values

c)

null values

d)

absolute values

18.

Which of the following options is NOT a relational operator?

a)

==

b)

!=

c)

&&

d)

>=

19.

Select the option to is equivalent to z-=10

a)

z = 10 - z

b)

z = z - 10

c)

All of the above

d)

NONE OF THESE

20.

If-else is an example of what kind of statement?


if (time < 18)

{ System.out.println("Good day."); }

else

{ System.out.println("Good evening."); }

a)

Expression Statement

b)

Block Statement

c)

Selection Statement

d)

Return Statement

21.

When will you use a "while loop"?

a)

If the number of iteration is not fixed

b)

If the number of iteration is not fixed and you must have to execute the loop at least once.

c)

If the number of iteration is fixed

d)

If the number of iteration is fixed and you must have to execute the loop at least once.

22.

When will you use a "do-while loop"?

a)

If the number of iteration is not fixed

b)

If the number of iteration is not fixed and you must have to execute the loop at least once.

c)

If the number of iteration is fixed

d)

If the number of iteration is fixed and you must have to execute the loop at least once.

23.

Of the following if statements, which one correctly executes two instructions if the condition is true?

a)

if (x < 0)

a = b * 2;

y = x;

b)

{ if (x <0)

a = b*2;

}

c)

if { (x < 0)

a = b * 2;

y = x; }

d)

if (x <0)

{ a = b*2;

y = x; }

24.

Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?

a)

if (x > 0) x++;

else x--;

b)

if (x > 0) x++;

else if (x < 0) x--;

c)

if (x > 0) x++;

if (x < 0) x--;

else x = 0;

d)

if (x == 0) x = 0;

else x++;

x--;

25.

If x is an int where x = 0, what will x be after the above loop terminates?

a)

64

b)

100

c)

128

d)

None of the above, this is an infinite loop

26.

Given the above code, where x = 0, what is the resulting value of x after the for-loop terminates?

for(int i=0; i<5; i++)

x += i;

a)

4

b)

5

c)

10

d)

15

27.

How many times will the above loop iterate?

a)

0

b)

9

c)

10

d)

11

28.

If the Loop-Continuation Condition is omitted in for/while statement, the executes ____________

a)

only one

b)

zero number of times

c)

infinite number of times

d)

Error

29.

Which of the following is Boolean Logical AND operator/ bitwise Operator?

a)

&

b)

&&

c)

|

d)

||

30.

Which of the following primitive data type is a 1-bit and has only two values: true and false

a)

char

b)

string

c)

int

d)

boolean

31.

The arithmetic operators +, -, *, /, and % perform mathematical operations on (a)   and values.

32.

(a)   provide a service to clients.

33.

Object behaviors are specified via (a)   .

34.

In the expression x + y, + is the operator, while x and y are its (a)   .

35.

The (a)   + and - require only a single operand.

36.

Arithmetic expressions mixing +, -, *, and/or / are evaluated in the same order as they are in ____________ _________________ .

(a)  

37.

_________ ________ follow the identifier naming rules.

(a)  

38.

Any (a)   operands are converted into strings.

39.

Java's statements involving (a)   with simple arithmetic modification have convenient abbreviations.

40.

Java's statements involving (a)   with simple arithmetic modification have convenient abbreviations.

41.

An object is an active agent that provides a service to (a)   .

42.

It is like a plan or (a)   that defines objects.

43.

(a)   must be created to provide a service to clients.

44.

The (a)   can be used to concatenate two strings.

45.

A parameter used in the method definition is called a __________ ______________.

(a)  

46.

Object values are called (a)   .

47.

As in ________________ _____________________, parentheses can be used to override the normal order of evaluation.

(a)  

48.

The (a)   associates a method call with a particular object.

49.

A (a)   defines the structure of an object.

50.

Like a mathematical function, a method can accept information via (a)   and compute a result.

51.

A (a)   is the user of an object.

52.

A (a)   has exactly one definition, but it can be invoked zero or more times.

53.

The types of a method's parameters must be specified within its (a)   .

54.

A method's result is indicated by a ____________ _________________.

(a)  

55.

(a)   come in three varieties: single line, multiple line, and documentation comments.

56.

The new operator creates an object from its ___________ ________________.

(a)  

57.

(a)   comments improve the readability of source code.

58.

Variables declared within a method are called _____________ __________________.

(a)  

59.

__________ _____________ elements are accessible anywhere; private class elements are only accessible within the class itself.

(a)  

60.

Local variables are isolated from all other variables within the (a)   or interactive session.

61.

A parameter used during a method invocation is called an ___________ __________________.

(a)  

62.

Who is the developer/founder of Java programming language?

a)

Rasmus Lerdorf

b)

James Gosling

c)

Dennis Ritchie

d)

Timothy Berners-Lee

63.

What are the following <<, >>, &, ^, | symbols?

a)

Bitwise Operators

b)

Comparison / Relational Operators

c)

Logical Operators

d)

Assignment Operators

64.

int x=32, y=2, z=0;

z = (x+100)*y;

z = (a)  

65.

int z = 300 % 10 *10;

z= (a)  

66.

int a=17, b=5;

int c=a/b+(a+b);

c = (a)  

67.

public static void main(String[] args) {

int a= ~10;

System.out.println(a);

}

(a)  

68.

A character with a backslash (\) just before it (ex. \n, \t, \r)

a)

special character

b)

reserved word

c)

user-defined word

d)

escape sequence

69.

What is the result of this statements?

int a=10, b=3;

System.out.println(a<<b);

(a)  

70.

What is the result of this statements?

int a=10, b=3;

System.out.println(a>>b);

(a)  

71.

What is the result of this statements?

int a=10, b=3;

System.out.println(a & b);

(a)  

72.

What is the result of this statements?

int a=10, b=3;

System.out.println(a ^ b);

(a)  

73.

What will be the output of the following Java code?

  1. class increment {

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

  2. int g = 3;

  3. System.out.print(++g * 8); }

  4. }

a)

32

b)

33

c)

24

d)

25

74.

What is the extension of compiled java classes?

a)

.txt

b)

.class

c)

.js

d)

.java

75.

What will be the output of the following Java program?

  1. final class A {

  2. int i;

  3. }

  4. class B extends A {

  5. int j;

  6. System.out.println(j + " " + i);

  7. }

  8. class inheritance

  9. {

  10. public static void main(String args[])

  11. {

  12. B obj = new B();

  13. obj.display();

  14. }

  15. }

a)

2 2

b)

3 3

c)

Runtime Error

d)

Compilation Error

76.

Here the class name is

(a)  

77.

memeber function name is

(a)  

78.

How do you call a method in Java?

a)

methodName();

b)

methodName[];

c)

(methodName);

d)

methodName;

79.

The value of a string variable can be surrounded by single quotes.

a)

true

b)

false

80.

The following are considerations if using if-else-if-else statement, which is not correct:

a)

An if can have zero or one else’s and it must come after any else if’s

b)

An if can have zero to many else if’s and they must come before else.

c)

Once an else if succeeds, none of the remaining else if’s or else’s will be tested.

d)

This statement can only have 2 to 3 elses.

81.

An If statement sometimes uses the form if condition then code, where condition is a Boolean expression and code is code that is executed if the condition is TRUE but if the condition is not true will give us FALSE statement result.

a)

TRUE

b)

FALSE

82.

We use if-else statements in making decisions in our programs but sometimes it is necessary to add additional conditions to accommodate several conditions in our programs that’s where if-else-if-else statement comes in

a)

TRUE

b)

FALSE

83.

Create an example of a for-each loop. Take this array as a base

String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};

---> please use i as a variable.

All you have to do is print the array but use a for-each is a must!

(a)  

84.

What is the purpose of camelCase in Java naming conventions?

a)
To comply with international naming standards
b)
To make variable names more readable and to distinguish words within the variable name.
c)
To confuse other programmers
d)
To make the code run faster
85.

Which of the following is true about Java identifiers?

a)
They can contain special characters
b)
They can start with a number
c)
They must start with a letter, underscore, or dollar sign
d)
They must be at least 10 characters long
86.

Explain the difference between int and double data types in Java.

a)

The int data type is used to store decimal values, while the double data type is used to store whole numbers.

b)

The int data type is used to store integer values, while the double data type is used to store floating-point numbers with decimal values.

c)

The int data type is used to store floating-point numbers, while the double data type is used to store integer values.

d)

The int data type is used to store both integer and floating-point numbers, while the double data type is used to store only integer values.

87.

What will be the output of the following code

import java.util.Arrays;

import java.util.Comparator;

public class ComparatorTest {

public static void main(String args[]){

String[] ar= {“c”,”d”,”b”,”a”,”e”};

InnerClass in=new InnerClass();

Arrays.parallelSort(ar, in);

for(String str : ar)

System.out.println(str +””);

System.out.println(Arrays.binarySearch(ar, “b”));

}

static class InnerClass implements Comparator<String>{

public int compare(String s1, String s2){

return s2.compareTo(s1);

}

}

}

a)

e d c b a -1

b)

a b c 0 e d

c)

d b c e a 1

d)

e b a d c

88.

What will be the output of the following code

import java.util.LinkedHashSet;

import java.util.Set;

public class LinkedHashSetTest {

public static void main (String args[]){

Set s=new LinkedHashSet();

s.add(“1”);s.add(1);

s.add(3);

s.add(2);

System.out.println(s);

}

}

a)

[1, 1, 2, 3]

b)

[1, 2, 2 3[

c)

[1, 1, 3, 2]

d)

[1, 2, 3]

89.

Indicate the actual output of the statements below:

int thisYear = 2019;

System.out.println("The current year is "+thisYear);

a)

The current year is thisYear

b)

The current year is 2019

c)

No output; an error exists

d)

The current year is2019

90.

Choose correct option.

a)

Base::show() called

b)

Derived::show() called

c)

Compiler Error

d)

Runtime Error