wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

MSTIP-JavaProgramming-FinalExam

Total questions: 100

Worksheet time: 2hrs 40mins

Name
Class
Date
1.

1. Which of this method is given parameter via command line arguments?

a)

a) main()

b)

b) recursive() method

c)

c) Any method

d)

d) System defined methods

2.

What are the Type Conversions available in Java language?

a)

A) Narrowing Type Conversion

b)

B) Widening Type Conversion

c)

A and B

d)

D) None of the above

3.

What is the output of the below Java code snippet?

char ch = 'A';//ASCII 65

int a = ch + 1;

ch = (char)a;

System.out.println(ch);

a)

A) 66

b)

B) A

c)

C) B

d)

D) 65

4.

Which type of loop is best known for its boolean condition that controls entry to the loop?

a)

A. do-while loop

b)

B. for (traditional)

c)

C. for-each

d)

D. while

5.

What will be the Output of the below code:

public class Demo{

public static void main(String[] arr){

}

public static void main(String arr){

}

}

a)

a) Nothing

b)

b) Error

c)

C) Finite

d)

d) Hii

6.

char is 2 byte in storage?

a)

True

b)

False

7.

Name the data type: '3'

a)

int

b)

char

c)

String

d)

None of the above

8.

What data type would you use for storing the number of students in a class?

a)

boolean

b)

String

c)

double

d)

int

9.
What data type would be best used to record an email address?
a)
String
b)
Integer
c)
Real
d)
Character
10.

What is the output of the following code snippet?

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

{ }

System.out.println(i);

a)

A. 5

b)

B. 0

c)

C. 4

d)

D. Compilation Error

11.

Function of the Scanner class to accept a float literal from the user is

a)

nextInt( )

b)

hasNext( )

c)

next( )

d)

nextFloat( )

12.

Predict the value of k,

int k =10;

k=k+k++;

a)

11

b)

20

c)

21

d)

22

13.
Which of these is not a Thread state?
a)
New
b)
Runnable
c)
sleep
d)
terminated
14.

Which of the following key word is optional in Exception handling program

a)

try

b)

catch

c)

finally

d)

throw

15.

What is an exception

a)

Error occurred during the execution of a program

b)

Bug occurred during the compile time of a program

c)

Simply an Error

d)

It is related to input values

16.

Exception classes belongs to following package

a)

import java.io.*

b)

import java.lang.*

c)

import java.util.*

d)

import java.lang.Exception.*

17.

Choose an exception if attempt to divide number by zero


int number = 89 / 0;

System.out.println("The answer is " + number);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundException

18.

class exception_handling

{ public static void main(String args[])

{ try

{ int a, b;

b = 0;

a = 5 / b;

System.out.print("A");

} catch(ArithmeticException e)

{ System.out.print("B");

}

finally

{ System.out.print("C");

}

}

}

a)

A

b)

B

c)

AC

d)

BC

19.

Find the output for the following.

public class IncDec

{

public static void main(String s[])

{

int a = 1;

int b = 2;

int c;

int d;


c = ++b;

d = a++;


c++;


System.out.println("a = " + a);

System.out.print("b = " + b);

System.out.println("c = " + c);

System.out.print("d = " + d);

}

}

a)

a = 2 b = 3 c = 4 d = 1

b)

a = 2 b = 3 c = 4 d = 1

c)

Program does not compile.

d)

a = 1 b = 2 c = 4 d = 2

20.

Java was developed by

a)

James gosling

b)

John gosling

c)

James frank

d)

John frank

21.

JDK stands for (a)  

22.

JVM stands for (a)  

23.

List out types of inheritance.

a)

Single

b)

Mulitple

c)

Multi level

d)

Hierarchy

24.

List out oops concept.

4 lines
25.

Which one of the following is escape sequences?

a)

\r

b)

\n

c)

\f

d)

\t

26.

Int data types represents _______ bits.

a)

8

b)

16

c)

32

d)

64

27.

There are (a)   types of data types.

28.

(a)   is a piece of memory that can contain a data value.

29.

How many types of array?

a)

1

b)

2

c)

3

d)

4

30.

What is the range of short data type in Java?

a)

-128 to 127

b)

-32768 to 32767

c)

-2147483648 to 2147483647

d)

None of the mentioned

31.

Modulus operator, %, can be applied to which of these?

a)

Integers

b)

Floating – point numbers

c)

Both Integers and floating – point numbers

d)

None of the mentioned

32.

class evaluate {

public static void main(String args[]) {

int a[] = {1,2,3,4,5}; int d[] = a; int sum = 0;

for (int j = 0; j < 3; ++j)

sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);

System.out.println(sum); } }

a)

38

b)

39

c)

41

d)

40

33.

Which of these can be returned by the operator &?

a)

Integer

b)

Boolean

c)

Character

d)

Integer or Boolean

34.

class dynamic_initialization {

public static void main(String args[]) {

double a, b; a = 3.0; b = 4.0;

double c = Math.sqrt(a * a + b * b);

System.out.println(c); } }

a)

5.0

b)

25.0

c)

7.0

d)

Compilation Error

35.

When Overloading does not occur?

a)

More than one method with same name but different method signature and different number or type of parameters

b)

More than one method with same name, same signature but different number of signature

c)

More than one method with same name, same signature, same number of parameters but different type

d)

More than one method with same name, same number of parameters and type but different signature

36.

Which of these statements are incorrect?

a)

Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms

b)

Assignment operators run faster than their equivalent long forms

c)

Assignment operators can be used only with numeric and character data type

d)

None of the mentioned

37.

class increment {

public static void main(String args[]) {

double var1 = 1 + 5;

double var2 = var1 / 4;

int var3 = 1 + 5;

int var4 = var3 / 4;

System.out.print(var2 + " " + var4); } }

a)

1 1

b)

0 1.5

c)

1.5 1

d)

1 1.5

38.

class increment {

public static void main(String args[]) {

int g = 3;

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

a)

24

b)

32

c)

25

d)

34

39.

class Output {

public static void main(String args[]) {

int a = 1; int b = 2; int c; int d;

c = ++b;

d = a++;

c++;

b++;

++a;

System.out.println(a + " " + b + " " + c); } }

a)

4 4 3

b)

3 3 4

c)

3 4 4

d)

4 3 3

40.

class bitwise_operator {

public static void main(String args[]) {

int var1 = 42;

int var2 = ~var1;

System.out.print(var1 + " " + var2); } }

a)

42 42

b)

42 -43

c)

43 42

d)

43 -42

41.

class bitwise_operator {

public static void main(String args[]) {

int a = 3;

int b = 6;

int c = a | b;

int d = a & b;

System.out.println(c + " " + d); } }

a)

7 2

b)

7 5

c)

5 7

d)

7 7

42.

class leftshift_operator {

public static void main(String args[]) {

byte x = 64; int i; byte y;

i = x << 2;

y = (byte) (x << 2)

System.out.print(i + " " + y); } }

a)

0 256

b)

256 0

c)

0 64

d)

256 1

43.

class rightshift_operator {

public static void main(String args[]) {

int x; x = 10;

x = x >> 1;

System.out.println(x); } }

a)

2

b)

7

c)

5

d)

10

44.

At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among “final, static, native, public, private, abstract, protected”

public interface Status {

/* insert qualifier here */ int MY_VALUE = 10;

}

a)

final, native, private

b)

final, static, protected

c)

final, private, abstract

d)

final, static, public

45.

What will be the output of the following Java program?

class Alligator {

public static void main(String[] args) {

int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};

int [][]y = x;

System.out.println(y[2][1]); } }

a)

2

b)

3

c)

7

d)

Compilation Error

46.

What will be the output of the following Java program?

class Abc {

public static void main(String[]args) {

String[] elements = { "for", "tea", "too" };

String first = (elements.length > 0) ? elements[0]: null; } }

a)

Compilation error

b)

An exception is thrown at run time

c)

The variable first is set to null

d)

The variable first is set to elements[0]

47.

What will be the output of the following Java program?

class selection_statements {

public static void main(String args[]) {

int var1 = 5; int var2 = 6;

if ((var2 = 1) == var1)

System.out.print(var2);

else

System.out.print(++var2); } }

a)

1

b)

3

c)

2

d)

5

48.

What will be the output of the following Java program?

class Output {

public static void main(String args[]) {

final int a=10,b=20;

while(a<b)

{

System.out.println("Hello"); }

System.out.println("World"); } }

a)

Hello

b)

run time error

c)

Hello world

d)

compile time error

49.

What will be the output of the following Java program?

class Alligator {

public static void main(String[] args) {

int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};

int [][]y = x;

System.out.println(y[2][1]); } }

a)

2

b)

3

c)

7

d)

Compilation Error

50.

class increment {

public static void main(String args[]) {

double var1 = 1 + 5;

double var2 = var1 / 4;

int var3 = 1 + 5;

int var4 = var3 / 4;

System.out.print(var2 + " " + var4); } }

a)

1 1

b)

0 1.5

c)

1.5 1

d)

1 1.5

51.

Which statement is true about java ?

a)

Java is a sequence-depended programming language

b)

Java is a code dependent programming language

c)

Java is a platform-dependent programming language

d)

Java is a platform-independent programming language

52.

Which component is used to compile,debug and execute the java programs ?

a)

JRE

b)

JIT

c)

JDK

d)

JVM

53.

Which one of the following is not a java feature

a)

Object-oriented

b)

Use of pointers

c)

Portable

d)

Dynamic and Extensible

54.

Which of these cannot be used for a variable name in java ?

a)

Identifier & keyword

b)

Identifier

c)

Keyword

d)

None of the mentioned

55.

Which of these are selection statements in java

a)

Break

b)

Continue

c)

For ( )

d)

If ( )

56.

Which of these keywords is used to define interfaces in java

a)

intf

b)

Intf

c)

interface

d)

Interface

57.

Which of the following is a superclass of every class in java ?

a)

ArrayList

b)

Abstract class

c)

Object class

d)

String

58.

Which of these statements is incorrect about tread ?

a)

Start() method is used to begin execution of the thread

b)

Run () method is used to begin execution of a thread before start() method in special cases

c)

A thread can be formed by implementing runnable interface only

d)

A thread can be formed by a class that extends thread class

59.

Which one of the following is not an access modifier ?

a)

Protected

b)

Void

c)

Public

d)

Private

60.

What is the numerical range of a char data tupe in java ?

a)

0 to 256

b)

-128 to 127

c)

0 to 65535

d)

0 to 32767

61.

When does method overloading is determined?

a)

At run time

b)

At compile time

c)

At coding time

d)

At execution time

62.

When overloading does not occur ?

a)

More than one method with same name but different method signature and different number or type of parameters

b)

More than one method with same name,same signature but different number of signature

c)

More than one method with same name,same signature,same number of parameters but different type

d)

More than one method with same , same number of parameters and type but different signature

63.

What is it called if an object has its own life cycle and there is no owner

a)

Aggregation

b)

Composition

c)

Encapsulation

d)

Association

64.

Which of the below is invalid identifier with the main method

a)

Public

b)

Static

c)

Private

d)

Final

65.

What is use of interpreter ?

a)

They covert bytecode to machine language code

b)

They read high level code and execute them

c)

They are intermediated between JIT and JVM

d)

It is a synonym for JIT

66.

How can we identify whether a compilation unit is class or interface from a .class file ?

a)

Java source file header

b)

Extension of compilation unit

c)

We cannot different between class and interface

d)

The class or interface name should be postfixed with unit type

67.

What will be the output?

a)

24

b)

32

c)

23

d)

31

68.

Java has (a)   primitive data types.

69.

Which one of the following is escape sequences?

a)

\r

b)

\n

c)

\f

d)

\t

70.

JDK stands for (a)  

71.

Java is

a)

Simple

b)

Object Oriented

c)

Platform dependent

d)

interpreted

72.
a)

a

b)

b

c)

c

d)

d

73.

byte is 1 byte size in storage?

a)

True

b)

False

74.

Long is 4 byte size in storage?

a)

True

b)

False

75.

char is 2 byte in storage?

a)

True

b)

False

76.

(=) sign means

a)

equals and it is used for math problems in Java

b)

assignment operator. It used to assign a value

77.

Which one is used for remainder in Java?

a)

/

b)

%

c)

+

d)

*

78.

int x = 3; in this case, which of the following statement is true?

a)

x = x+1;

b)

x++;

c)

x += 1;

d)

All of above

79.

This data type returns true or false

a)

String

b)

boolean

c)

char

d)

int

80.

Name the data type: 1.0

a)

double

b)

int

c)

char

d)

boolean

81.

What data type would you use for storing the average test score in a class?

a)

boolean

b)

char

c)

int

d)

double

82.

How would you declare a variable storing the tax rate?

a)

int taxRate = 5.1;

b)

taxRate = "5.1";

c)

double taxRate = 5.1;

d)

double taxRate = "5.1";

83.

How would you declare a variable that tells you that someone passed a class?

a)

boolean passed = 'true';

b)

boolean passed = true;

c)

passed = true;

d)

String passed = "true";

84.

Name the data type: "true"

a)

boolean

b)

char

c)

String

d)

double

85.

Name the data type: '3'

a)

int

b)

char

c)

String

d)

None of the above

86.

Name the data type: false

a)

String

b)

boolean

c)

int

d)

None of the above

87.

What data type would you use for storing the number of students in a class?

a)

boolean

b)

String

c)

double

d)

int

88.
Variables and constants in programs need to be assigned a data type.
a)
True
b)
False
89.
Expressions cannot contain variables of different data types.
a)
False
b)
True
90.
Integers cannot store negative numbers.
a)
False
b)
True
91.
If you store a smaller number in an integer, (say 10 instead of 1234,) it will take up less memory.
a)
False
b)
True
92.
What data type would be best used to record an email address?
a)
String
b)
Integer
c)
Real
d)
Character
93.
What data type would be the answer to the expression x < 5?
a)
Boolean
b)
Character
c)
Real
d)
String
94.

What is the correct format of coding in Java?

a)

type variable = value;

b)

Variable = value;

c)

type = value;

d)

type variable;

95.

It is a sequence of characters.

a)

Str

b)

Int

c)

string

d)

integer

96.

It is a syntax used to print your output

a)

system.out.printline

b)

system.out.prntlne

c)

System.out.println

d)

System.out.printline

97.

Java statements: write the if else if statement, consider writing (expression) and {statements}

(a)  

98.

Java Statements:

Write the Do-While Loop

consider writting statements and expression

also remember --> ;

(a)  

99.

Check what is it missing in the for loop?

for(int = 0; i < max ++ i ){

statements

}

SELECT the correct one.

a)

for( int=0; i max; ++i ){

statements

}

b)

for(int i i < max; ++i ){

statements

}

c)

for(int i=0; i < max; ++i ){

statements

}

d)

for(int i=0; i < max ++i;){

statements

}

100.

Java Boolean Operators

from left to right select the names

! x x && y x || y

a)

not, and, or

b)

not, or, and

c)

not, and, and

d)

and, not, or