NEW
Font size
WorksheetsQUIZ DAILY JAVA CORE
Total questions: 26
Worksheet time: 20mins
What is the output of these statements?
class OperatorExample{
public static void main(String args[]){
int a=10;
int b=20;
a+=4;
b-=4;
System.out.println(a);
System.out.println(b);
}}
A. 4 and 4
B. 14 and 4
C. 14 and 16
D. 14 and 24
What is the output of these statements?
for (int i = 1; i <= 10; ++i) {
System.out.print(i);
}
A. 2345678910
B. 23456789
C. 234567891011
D. 12345678910
Which of the following opinion is TRUE about break and continue statement?
A. continue leaves a loop, break jumps to the next iteration.
B. break skips the current iteration of a for, while , or do-while loop
C. break leaves a loop, continue jumps to the next iteration.
D. None of the above
What is the output of these statements?
for(int i=0;i<10;i++)
{
if (i==4)
{
break;
}
System.out.print(i);
}
A. 012
B. 0123
C. 01234
D. None of the above
What is the output of these statements?
for(int i=0;i<10;i++)
{
if (i==4)
{
continue;
}
System.out.print(i+"\t");
}
A. 0123
B. 01234
C. 012356789
D. None of the above
Types of Java Comments include:
A. Single Line Comment
B. Multi Line Comment
C. Documentation Comment
D. A and B are TRUE
E. A, B and C are TRUE
What type of sorting with following statements?
static void mySort(int[] arr) {
int n = arr.length;
int temp = 0;
for(int i=0; i < n; i++){
for(int j=1; j < (n-i); j++){
if(arr[j-1] > arr[j]){
//swap elements
temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
}
}
}
A. BubbleSort
B. SelectionSort
C. InsertionSort
D. None of the above
What type of sorting with following statements?
public static void mySort(int[] arr){
for (int i = 0; i < arr.length - 1; i++)
{
int index = i;
for (int j = i + 1; j < arr.length; j++){
if (arr[j] < arr[index]){
index = j;//searching for lowest index
}
}
int smallerNumber = arr[index];
arr[index] = arr[i];
arr[i] = smallerNumber;
}
}
A. BubbleSort
B. SelectionSort
C. InsertionSort
D. None of the above
What type of sorting with following statements?
public static void mySort(int array[]) {
int n = array.length;
for (int j = 1; j < n; j++) {
int key = array[j];
int i = j-1;
while ( (i > -1) && ( array [i] > key ) ) {
array [i+1] = array [i];
i--;
}
array[i+1] = key;
}
}
A. BubbleSort
B. SelectionSort
C. InsertionSort
D. None of the above
Which opinion is TRUE about naming conventions in java?
A. class name should start with uppercase letter and be a noun
B. interface name should start with uppercase letter and be an adjective
C. method name should start with lowercase letter and be a verb
D. variable name should start with lowercase letter
E. All of the above
The object cloning is a way to create exact copy of an object?
A. True
B. False
class C {
public static void main(String[] args) {
int[] a1 = new int[]; // 1
int a2[] = new int[5]; // 2
int[] a3 = new int[]{1,2}; // 3
int []a4 = {1,2}; // 4
}}
Compile-time errors are generated at which lines?
A. 1
B. 2
C. 3
D. 4
class M {
public static void main(String[] args) {
int[] a1 = {1,2,3};
int []a2 = {4,5,6};
int a3[] = {7,8,9};
System.out.print(a1[1]+","+a2[1]+","+a3[1]);
}}
What is the result of attempting to compile and run the program?
A. Prints: 12
B. Prints: 1,4,7
C. Prints: 2,5,8
D. Prints: 3,6,9
class E {
static boolean a, b, c;
public static void main (String[] args) {
boolean x = (a = true) || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}}
What is the result of attempting to compile and run the program?
A. Prints: false,false,false
B. Prints: false,false,true
C. Prints: false,true,false
D. Prints: true,false,false
class E {
static boolean a, b, c;
public static void main (String[] args) {
boolean x = a || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}}
What is the result of attempting to compile and run the program?
A. Prints: false,false,false
B. Prints: false,false,true
C. Prints: false,true,true
D. Prints: false,true,false
class E {
public static void main (String[] args) {
byte x = 3, y = 5;
System.out.print((y % x) + ",");
System.out.print(y == (y/x) + (x+1));
}}
What is the result of attempting to compile and run the program?
A. Prints: 1,true
B. Prints: 2,true
C. Prints: 1,false
D. Prints: 2,false
class E {
static int m(int i) {System.out.print(i + ","); return 0;}
public static void main (String[] args) {
int i = 0; i = i++ + m(i); System.out.print(i);
}}
What is the result of attempting to compile and run the above program?
A. Prints: 0,0
B. Prints: 1,0
C. Prints: 0,1
D. Prints: 1,1
class E {
public static void main(String args[]) {
int a = 1; a += ++a + a++; System.out.print(a);
}}
What is the result of attempting to compile and run the above program?
A. Prints: 3
B. Prints: 4
C. Prints: 5
D. Prints: 6
class M {
public static void main(String[] args) {
int[][] a1 = {{1,2,3},{4,5,6},{7,8,9,10}};
System.out.print(a1[0][2]+","+a1[1][0]+","+a1[2][1]);
}}
What is the result of attempting to compile and run the program?
A. Prints: 3,4,8
B. Prints: 7,2,6
C. Compile-time error
D. Run-time error
class A {
public static void main(String[] args) {
char a = 'a', b = 'b'; // 'a' = 97, 'b' = 98
System.out.print(a + b + "" + a + b);
}}
What is the result of attempting to compile and run the program?
A. Prints: 390
B. Prints: 195195
C. Prints: 195ab
D. Prints: ab195
class M {
public static void main (String[] args) {
int a = 1; // 1
short b = 1; // 2
long c = b + a; //3
a = c + a; // 4
}}
A compile-time error is generated at which line?
A. 1
B. 2
C. 3
D. 4
class A {
public static void main(String[] args) {
boolean b = true;
if (b = false) {System.out.print("A");
} else if (b) {System.out.print("B");
} else {System.out.print("C");}
}}
What is the result of attempting to compile and run the program?
A. Prints: A
B. Prints: B
C. Prints: C
D. Compile error
class F {
public static void main (String[] args) {
for (int i = 0; i < 4; i++) {
switch (i) {
case 0: System.out.print("A");
case 1: System.out.print("B");
case 2: System.out.print("C");
}}}}
What is the result of attempting to compile and run the program?
A. Prints: ABC
B. Prints: ABCC
C. Prints: CBA
D. Prints: ABCBCC
class F {
public static void main (String[] args) {
int j = 0;
for (int i = 0; i < 2; i++) do
System.out.print(i);
while (j++ < 2);
}}
What is the result of attempting to compile and run the program?
A. Prints: 0001
B. Prints: 012
C. Prints: 012012
D. Prints: 012345
Which of the following is not primitive data type?
A. byte
B. short
C. enum
D. int
Local variable which is?
A. is declared inside the class but outside the method
B. is declared inside the method
C. All of the above
