Font size
WorksheetsJava Quiz
Total questions: 40
Worksheet time: 22mins
Array is
immutable
mutable
always contant
Which of the following declares an array of int named img?
int img;
int[] img;
new int img[];
int img = int[];
What are the legal indexes for the array ar, given the following declaration:
int[] ar = {2, 4, 6, 8 };
0, 1, 2, 3
1, 2, 3, 4
2, 4, 6, 8
0, 2, 4. 6
What is the output of the following code fragment:
int[] ar = {2, 4, 6, 8 };
System.out.println( ar[0] + " " + ar[1] );
2 6
8
2 4
6 8
What is the output of the following code fragment:
int[] ar = {2, 4, 6, 8 };
ar[0] = 23;
ar[3] = ar[1];
System.out.println( ar[0] + " " + ar[3] );
23 2
2 8
31
23 4
What is the output of the following code fragment:
int[] y = new int[5];
y[0] = 34;
y[1] = 88;
System.out.println( y[0] + " " + y[1] + " " + y[5] );
34 88 0
34 88 88
The program is defective and will not compile
0 34 88
What is the output of the following code fragment:
int[] z = new int[9];
z[0] = 7;
z[1] = 3;
z[2] = 4;
System.out.println( z[0] + z[1] + " " + z[5] );
10 0
7 3 0
The program is defective and will not compile.
7 3 4
What is the output of the following code fragment:
int[] zip = new int[5];
zip[0] = 7;
zip[1] = 3;
zip[2] = 4;
zip[3] = 1;
zip[4] = 9;
System.out.println( zip[ 2 + 1 ] );
4 3
3
4
1
What is the output of the following code fragment:
int[] zip = new int[5];
zip[0] = 7;
zip[1] = 3;
zip[2] = 4;
zip[3] = 1;
zip[4] = 9;
int j = 3;
System.out.println( zip[ j-1 ] );
7
3
4
1
How many objects are present after the following code fragment has executed?
double[] ann = new double[ 7 ];
double[] bob;
bob = ann;
2
7
14
1
Which of the following is a comment in the Java language?
/ comment /
/* comment */
/ comment */
<-- comment -->
Which of the following is the correct main() method signature in Java?
public static void main (String [] args)
public static void Main (String [] args)
public static void main (string [] args)
public static void main (String args)
Which of the following is a valid variable declaration in Java?
int 1myInteger = 0;
int int = 0;
Int my Integer = 0;
int myInteger = 0;
Which Java data type is used to store 64-bit floating-point numbers?
int
long
float
double
Which of the following is a reserved word in Java?
export
import
input
output
What is a class in object-oriented programming?
A class is a template with data and methods
A class is a package
A class is the declared object in memory
A class is a reference object in memory
What is the output of this program?
0
1
StackOverFlow
NullPointerException
Which component is used to compile, debug and execute java program?
JVM
JDK
JIT
JRE
Which of the following is not a rule that must be followed when naming identifiers?
After the first character, you may use the letters a-z, A-Z, an underscore, a dollar sign, or digits 0-9.
Identifiers can contain spaces.
Uppercase and lowercase characters are distinct.
The first character must be one of the letters a-z, A-Z, an underscore or a dollar sign.
Java was originally named:
Coffee
Oak
New C++
Duke
Which of these variable types is not numeric?
boolean
char
double
int
How many times will this loop run?
int x = 0;
while(x < 4) {
x = x + 1;
}
0
3
4
5
How many times will this loop run?
int x = 4;
while(x < 4) {
x = x + 1;
}
0
3
4
5
Pick the correct code for taking String input from the keyboard.
Scanner input = new Scanner(System.in);
String str = input.nextLine();
String str = input.nextInt();
int number = input.nextInt();
int number = input.nextLine();
ar, given the following declaration:int[] ar = {2, 4, 6, 8 }0, 1, 2, 31, 2, 3, 40, 2, 4, 6For the array:
int stats[3];
What is the range of the index?
0 to 3
0 to 2
1 to 3
0 to 4
int [] nums = {2, 3, 5, 8, 9, 11};
How would you access the fourth element in nums?
nums[4]
nums[3]
nums(4)
nums(3)
Who invented Java?
James Gosling
Sergey Brin
Steve Jobs
Bill Gates
Tim Berners-Lee
Which of the following is not a Java features?
Dynamic
Architecture Neutral
Use of pointers
Object-oriented
Which of the following is a valid declaration of a char?
char ch = '\utea';
char ca = 'tea';
char cr = \u0223;
char cc = '\itea';
When does method overloading is determined?
At run time
At compile time
At coding time
At execution time
Which concept of Java is a way of converting real world objects in terms of class?
Polymorphism
Encapsulation
Abstraction
Inheritance
Which concept of Java is achieved by combining methods and attribute into a class?
Encapsulation
Inheritance
Polymorphism
Abstraction
Syntax to compile java program from command prompt
java Filename.java
javac Filename
javac Filename.java
java Filename
