Font size
WorksheetsMSTIP-JavaProgramming-FinalExam
Total questions: 100
Worksheet time: 2hrs 40mins
1. Which of this method is given parameter via command line arguments?
a) main()
b) recursive() method
c) Any method
d) System defined methods
What are the Type Conversions available in Java language?
A) Narrowing Type Conversion
B) Widening Type Conversion
A and B
D) None of the above
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) 66
B) A
C) B
D) 65
Which type of loop is best known for its boolean condition that controls entry to the loop?
A. do-while loop
B. for (traditional)
C. for-each
D. while
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) Nothing
b) Error
C) Finite
d) Hii
char is 2 byte in storage?
True
False
Name the data type: '3'
int
char
String
None of the above
What data type would you use for storing the number of students in a class?
boolean
String
double
int
What is the output of the following code snippet?
int i = 0; for(i = 0 ; i < 5; i++)
{ }
System.out.println(i);
A. 5
B. 0
C. 4
D. Compilation Error
Function of the Scanner class to accept a float literal from the user is
nextInt( )
hasNext( )
next( )
nextFloat( )
Predict the value of k,
int k =10;
k=k+k++;
11
20
21
22
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
What is an exception
Error occurred during the execution of a program
Bug occurred during the compile time of a program
Simply an Error
It is related to input values
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Choose an exception if attempt to divide number by zero
int number = 89 / 0;
System.out.println("The answer is " + number);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException
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
B
AC
BC
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 = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
Java was developed by
James gosling
John gosling
James frank
John frank
JDK stands for (a)
JVM stands for (a)
List out types of inheritance.
Single
Mulitple
Multi level
Hierarchy
List out oops concept.
Which one of the following is escape sequences?
\r
\n
\f
\t
Int data types represents _______ bits.
8
16
32
64
There are (a) types of data types.
(a) is a piece of memory that can contain a data value.
How many types of array?
1
2
3
4
What is the range of short data type in Java?
-128 to 127
-32768 to 32767
-2147483648 to 2147483647
None of the mentioned
Modulus operator, %, can be applied to which of these?
Integers
Floating – point numbers
Both Integers and floating – point numbers
None of the mentioned
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); } }
38
39
41
40
Which of these can be returned by the operator &?
Integer
Boolean
Character
Integer or Boolean
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); } }
5.0
25.0
7.0
Compilation Error
When Overloading does not occur?
More than one method with same name but different method signature and different number or type of parameters
More than one method with same name, same signature but different number of signature
More than one method with same name, same signature, same number of parameters but different type
More than one method with same name, same number of parameters and type but different signature
Which of these statements are incorrect?
Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms
Assignment operators run faster than their equivalent long forms
Assignment operators can be used only with numeric and character data type
None of the mentioned
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); } }
1 1
0 1.5
1.5 1
1 1.5
class increment {
public static void main(String args[]) {
int g = 3;
System.out.print(++g * 8); } }
24
32
25
34
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); } }
4 4 3
3 3 4
3 4 4
4 3 3
class bitwise_operator {
public static void main(String args[]) {
int var1 = 42;
int var2 = ~var1;
System.out.print(var1 + " " + var2); } }
42 42
42 -43
43 42
43 -42
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); } }
7 2
7 5
5 7
7 7
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); } }
0 256
256 0
0 64
256 1
class rightshift_operator {
public static void main(String args[]) {
int x; x = 10;
x = x >> 1;
System.out.println(x); } }
2
7
5
10
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;
}
final, native, private
final, static, protected
final, private, abstract
final, static, public
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]); } }
2
3
7
Compilation Error
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; } }
Compilation error
An exception is thrown at run time
The variable first is set to null
The variable first is set to elements[0]
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); } }
1
3
2
5
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"); } }
Hello
run time error
Hello world
compile time error
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]); } }
2
3
7
Compilation Error
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); } }
1 1
0 1.5
1.5 1
1 1.5
Which statement is true about java ?
Java is a sequence-depended programming language
Java is a code dependent programming language
Java is a platform-dependent programming language
Java is a platform-independent programming language
Which component is used to compile,debug and execute the java programs ?
JRE
JIT
JDK
JVM
Which one of the following is not a java feature
Object-oriented
Use of pointers
Portable
Dynamic and Extensible
Which of these cannot be used for a variable name in java ?
Identifier & keyword
Identifier
Keyword
None of the mentioned
Which of these are selection statements in java
Break
Continue
For ( )
If ( )
Which of these keywords is used to define interfaces in java
intf
Intf
interface
Interface
Which of the following is a superclass of every class in java ?
ArrayList
Abstract class
Object class
String
Which of these statements is incorrect about tread ?
Start() method is used to begin execution of the thread
Run () method is used to begin execution of a thread before start() method in special cases
A thread can be formed by implementing runnable interface only
A thread can be formed by a class that extends thread class
Which one of the following is not an access modifier ?
Protected
Void
Public
Private
What is the numerical range of a char data tupe in java ?
0 to 256
-128 to 127
0 to 65535
0 to 32767
When does method overloading is determined?
At run time
At compile time
At coding time
At execution time
When overloading does not occur ?
More than one method with same name but different method signature and different number or type of parameters
More than one method with same name,same signature but different number of signature
More than one method with same name,same signature,same number of parameters but different type
More than one method with same , same number of parameters and type but different signature
What is it called if an object has its own life cycle and there is no owner
Aggregation
Composition
Encapsulation
Association
Which of the below is invalid identifier with the main method
Public
Static
Private
Final
What is use of interpreter ?
They covert bytecode to machine language code
They read high level code and execute them
They are intermediated between JIT and JVM
It is a synonym for JIT
How can we identify whether a compilation unit is class or interface from a .class file ?
Java source file header
Extension of compilation unit
We cannot different between class and interface
The class or interface name should be postfixed with unit type
What will be the output?
24
32
23
31
Java has (a) primitive data types.
Which one of the following is escape sequences?
\r
\n
\f
\t
JDK stands for (a)
Java is
Simple
Object Oriented
Platform dependent
interpreted
a
b
c
d
byte is 1 byte size in storage?
True
False
Long is 4 byte size in storage?
True
False
char is 2 byte in storage?
True
False
(=) sign means
equals and it is used for math problems in Java
assignment operator. It used to assign a value
Which one is used for remainder in Java?
/
%
+
*
int x = 3; in this case, which of the following statement is true?
x = x+1;
x++;
x += 1;
All of above
This data type returns true or false
String
boolean
char
int
Name the data type: 1.0
double
int
char
boolean
What data type would you use for storing the average test score in a class?
boolean
char
int
double
How would you declare a variable storing the tax rate?
int taxRate = 5.1;
taxRate = "5.1";
double taxRate = 5.1;
double taxRate = "5.1";
How would you declare a variable that tells you that someone passed a class?
boolean passed = 'true';
boolean passed = true;
passed = true;
String passed = "true";
Name the data type: "true"
boolean
char
String
double
Name the data type: '3'
int
char
String
None of the above
Name the data type: false
String
boolean
int
None of the above
What data type would you use for storing the number of students in a class?
boolean
String
double
int
What is the correct format of coding in Java?
type variable = value;
Variable = value;
type = value;
type variable;
It is a sequence of characters.
Str
Int
string
integer
It is a syntax used to print your output
system.out.printline
system.out.prntlne
System.out.println
System.out.printline
Java statements: write the if else if statement, consider writing (expression) and {statements}
(a)
Java Statements:
Write the Do-While Loop
consider writting statements and expression
also remember --> ;
(a)
Check what is it missing in the for loop?
for(int = 0; i < max ++ i ){
statements
}
SELECT the correct one.
for( int=0; i max; ++i ){
statements
}
for(int i i < max; ++i ){
statements
}
for(int i=0; i < max; ++i ){
statements
}
for(int i=0; i < max ++i;){
statements
}
Java Boolean Operators
from left to right select the names
! x x && y x || y
not, and, or
not, or, and
not, and, and
and, not, or
