Font size
WorksheetsJava
Total questions: 100
Worksheet time: 3570secs
Java was originally named:
Coffee
Oak
New C++
Duke
Who invented Java?
James Gosling
Sergey Brin
Steve Jobs
Bill Gates
Tim Berners-Lee
_________ operator returns the remainder after division
+
/
%
*
Operator used to access the members of a class /package
(.) Dot
(,) Comma
Java is
platform dependent
platform indeprndent
Java programs ________________
are only compiled
are only compiled not interpreted
are only interpreted
are both compiled and interpreted
In Java, execution starts from ___________ function.
get()
main()
java()
display()
++ increases the value of a variable by 1
assignment operator
decrement operator
increment operator
sentinel
What's the value of below?
int i=5;
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
5
6
7
6
6
7
6
7
8
5
5
6
What index value is used to locate the last element in the nums ArrayList?
nums.size()-1
nums.length()-1
nums.size()
nums.length
Which statement below is the correct way to retrieve the first element in the nums ArrayList?
nums.get(0)
nums[0]
nums(0)
nums[1]
Identify the error that exist in this method program:-
Wrong use of return method type
variable extra was unknown.
doble is not one of the data type
A wrong use of hour data type.
ar, given the following declaration:int[] ar = {2, 4, 6, 8 }0, 1, 2, 31, 2, 3, 40, 2, 4, 6What is the output of this program?
0
1
120
None of the above
How many stars are printed?
7
3
4
5
Infinite Loop
In total, how many times is the inner loop executed?
5
10
15
50
Infinite Loop
It is an optional statement used to describe what a program or a line of program is doing.
tag
command
code
comment
Which of the followings is Java code that starts from the main() method as a mandatory part of every program
public void static main(String args [])
public void main static (args[] String)
public static void main (String args[])
public static void main [String [] Args]
A Java statement is one or more lines of code terminated by a semicolon. True or False?
False
True
A Java block is formed by enclosing statements by open and close parentheses. True or False?
True
False
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
try block may or may not contains catch blocks
True
False
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
int len = "jump it!".length();
What is the value of len?
8
7
9
6
This code does not compile.
String s1 = "hello";
String s2 = new String("hello");
if (s1 == s2) System.out.print("Hey");
else System.out.print("Yo");
What is the output?
Hey
Yo
There is no output.
This code will not compile.
Generally string is a sequence of characters, But in java, string is an _______.
Object
Class
Package
None of the above
Which inheritance is not supported in java?
Multiple
Multilevel inheritance
Hybrid
Java supports all of the above
Which data type is not supported by ArrayList?
Integer
String
double
Boolean
What is an instance of a class?
Class
Object
Reference
Primitive
Is "X" printed?
YES
NO
Which one of the following is a valid statement?
char[] c = new char();
char[] c = new char[5];
char[] c = new char(4);
char[] c = new char[];
Which component is used to compile, debug and execute java program?
JVM
JDK
JRE
JIT
Which component is responsible for converting bytecode into machine specific code
JVM
JDK
JRE
JIT
Which component is responsible to run java program
JVM
JDK
JRE
JIT
Java is ______________________
Object based
Object Oriented
fully object oriented
procedural
--------- is a symbol, that operates on operands and produce a result
operands
variables
operators
Ternary
What is the result of 13<=13 ?
True
False
Both true and false
None
Syntax for main method
void main()
void main(String[] args)
public static void main(String[] args)
public main(String[] args)
Which of these are selection statements in Java?
if()
for
continue
break
Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?
for
while
do..while
None of the above
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
2
3
4
Which of the statement test only for equality?
if
switch
if & switch
None of the above
What will be the output of the following program.
class WeekDays
{
public static void main(String s[])
{
int day = 4;
switch(day)
{
case 1:
System.out.println("Monday");
case 2:
System.out.println("Tuesday");
case 3:
System.out.println("Wednesday");
case 4:
System.out.println("Thursday");
case 5:
System.out.println("Friday");
default:
System.out.println("Weekend");
break;
}
}
}
Thursday
Compilation Error
Thursday
Friday
Weekend
Runtime error
What will be the output of the following program.
class WeekDays
{
public static void main(String s[])
{
int day = 7;
switch(day)
{
case 1:
System.out.println("Monday");
case 2:
System.out.println("Tuesday");
case 3:
System.out.println("Wednesday");
case 4:
System.out.println("Thursday");
case 5:
System.out.println("Friday");
}
}
}
No Output
Compilation Error
Sunday
Runtime error
What will the following code segment print?
System.out.println(17 % 3);
(a)
What will be the value in variable x after this code segment is executed?
double x = 5.0 + 2;
7
7.0
There will be a runtime error
There will be a syntax error
5.02
Find the output
class Test {
public static void main(String args[]) {
int arr[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
Compile error
Exception
Garbage value
Garbage value
0
0
What will be the array after executing this line ?
names[1] = "Sarah";
What is the correct way to initialize an array with 10 positions?
int numbers = new int[10];
int[] numbers = new int[];
int[] numbers = new int[10];
int[10] numbers = new int[10];
In an array, the index of the first element is (a)
catch block is used to
throw an exception
create an exception
handles an exception
stops execution
Abstract class can have
Abstract methods
Methods with code implementation
Used to create objects
Used to create subclasses
What are the values of var1 and var2 when the code finishes executing?
var1 = 1, var2 = 1
var1 = 2 , var2 = 0
var1 = 3, var2 = -1
var1 = 0, var2 = 2
The loop will cause a run-time error for division by zero
Which are the types of operators seen? Select as many you think
bitwise operator
subtraction operator
equality operator
arithmetic operator
select as many unary arithmetic operators as you see
==
--
||
!
which description of these relational operators are incorrect?
==(equal to)
<(less than)
>=(greater than)
!=(less than equal to)
which type of operator it is? i + =5
addition assignment operator
conditional operator
arithmetic operator
equality operator
Which of the following can be operands of arithmetic operators?
Numeric
Boolean
Both Numeric & Characters
Characters
Bytecode can be understood by the ________________________
Any Machine
Java Machine
Virtual Machine
Will this code compile?
Yes
No
Will this code compile?
Yes
No
Will this code compile without error?
Yes
No
Will this code compile?
Yes
No
What will happen when you run and compile the following code?
1
0
compilation error
runtime error
What will happen when you run and compile the following code?
Hello
Compilation error
Runtime error
None of the above
What will happen when you run and compile the following code?
Hi
Compilation error
No output
Runtime error
Which class has defined the equals(object o) method?
String
Object
Main
System
What will happen when you compile and run the following code?
Int version
Long version
Compilation error
Runtime error
Which statement is true for the following code?
The code will compile without changes.
The code will compile if public tree{} {Plant{}:} is added to the tree class
The code will compile if public tree{} {tree{}:} is added to the Plant class
The code will compile if public plant{} {this {"fern"}:} is added to the Plant class
what will be the result of the following code?
Int long
Short long
Compilation fails
An exception is thrown at the runtime
Which three methods, inserted individual at line 14, will correctly complete class 2
Int foo{}{/*more code here*/.}
Void foo{}{/*more code here*/.}
Public void foo{}{/*more code here*/.}
Private void foo{}{/*more code here*/.}
Protected void foo{}{/*more code here*/.}
How do you insert COMMENTS in Java code?
# This is a comment
/* This is a comment
// This is a comment
How to declare a Static variable
int a= 10;
static a= 200;
static int a= 100;
How to declare a Static variable
int a= 10;
static a= 200;
static int a= 100;
Static variable is a Global variable
True
False
NonStatic Variable is a Local Variable
True
False
Where can we declare a Static Variable
inside main function
outside main function
Where can we declare a nonStatic Variable
inside main function
outside main function
Where can we declare Local Variable
inside main function
outside main function
Can static and nonStatic variables declared as public
Yes
No
is Local Variable and NonStatic variable are same
True
Local
Can i have the same Global variable name for my Local Variable
Yes
No
How to create an Object for my Class "Abc"
Abc obj= new Abc;
Abc = new Abc;
Abc obj= new Abc();
In Java , Data types are
Primitive data type
Non Primitive data type
Both are correct
Both are incorrect
Java Access Modifiers are
public,Private
Protected
Default
All of these
Math class is a part of Java.________ package
io
util
lang
All mathematical functions are included in a class called
Math
System
Scanner
This function returns the maximum of 2 numbers
Math.min()
Math.max()
Math.minmax()
Which of the following are Java features?
Object- oriented programming
Class- based programming
Bytecode is platform independent
All of above
Which laboratory was Java invented or developed in?
Bell Laboratory
Sun Microsystems
Dennis Ritchie Office
Johnson and Johnson
Which of the below is valid way to instantiate an array in java?
int myArray [] = {1, 3, 5};
int [] myArray = {“1”, “2”, “3”};
int myArray [] [] = {1,2,3,4};
int [] myArray = (5, 4, 3);
What are the valid statements for static keyword in Java?
We can have static block in a class.
The static block in a class is executed every time an object of class is created.
We can have static method implementations in interface.
We can define static block inside a method.
