wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

QUIZ DAILY JAVA CORE

Total questions: 26

Worksheet time: 20mins

Name
Class
Date
1.

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)

A. 4 and 4

b)

B. 14 and 4

c)

C. 14 and 16

d)

D. 14 and 24

2.

What is the output of these statements?

for (int i = 1; i <= 10; ++i) {     

System.out.print(i);

}

a)

A. 2345678910

b)

B. 23456789

c)

C. 234567891011

d)

D. 12345678910

3.

Which of the following opinion is TRUE about break and continue statement?

a)

A. continue leaves a loop, break jumps to the next iteration.

b)

B. break skips the current iteration of a for, while , or do-while loop

c)

C. break leaves a loop, continue jumps to the next iteration.

d)

D. None of the above

4.

What is the output of these statements? 

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

  {    

  if (i==4)     

   {     

       break;  

      }    

    System.out.print(i);  

  }

a)

A. 012

b)

B. 0123

c)

C. 01234

d)

D. None of the above

5.

What is the output of these statements? 

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

  {       

if (i==4)     

   {      

      continue;   

     }    

    System.out.print(i+"\t");  

  }

a)

A. 0123

b)

B. 01234

c)

C. 012356789

d)

D. None of the above

6.

Types of Java Comments include:

a)

A. Single Line Comment

b)

B. Multi Line Comment

c)

C. Documentation Comment

d)

D. A and B are TRUE

e)

E. A, B and C are TRUE

7.

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)

A. BubbleSort

b)

B. SelectionSort

c)

C. InsertionSort

d)

D. None of the above

8.

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)

A. BubbleSort

b)

B. SelectionSort

c)

C. InsertionSort

d)

D. None of the above

9.

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)

A. BubbleSort

b)

B. SelectionSort

c)

C. InsertionSort

d)

D. None of the above

10.

Which opinion is TRUE about naming conventions in java?

a)

A. class name should start with uppercase letter and be a noun

b)

B. interface name should start with uppercase letter and be an adjective

c)

C. method name should start with lowercase letter and be a verb

d)

D. variable name should start with lowercase letter

e)

E. All of the above

11.

The object cloning is a way to create exact copy of an object?

a)

A. True

b)

B. False

12.

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)

A.  1

b)

B.  2

c)

C.  3

d)

D.  4

13.

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)

A.  Prints: 12

b)

B.  Prints: 1,4,7

c)

C.  Prints: 2,5,8

d)

D.  Prints: 3,6,9

14.

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)

A.  Prints: false,false,false

b)

B.  Prints: false,false,true

c)

C.  Prints: false,true,false

d)

D.  Prints: true,false,false

15.

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)

A.  Prints: false,false,false

b)

B.  Prints: false,false,true

c)

C.  Prints: false,true,true

d)

D.  Prints: false,true,false

16.

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)

A.  Prints: 1,true

b)

B.  Prints: 2,true

c)

C.  Prints: 1,false

d)

D.  Prints: 2,false

17.

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)

A.  Prints: 0,0

b)

B.  Prints: 1,0

c)

C.  Prints: 0,1

d)

D.  Prints: 1,1

18.

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)

A.  Prints: 3

b)

B.  Prints: 4

c)

C.  Prints: 5

d)

D.  Prints: 6

19.

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)

A.  Prints: 3,4,8

b)

B.  Prints: 7,2,6

c)

C.  Compile-time error

d)

D.  Run-time error

20.

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)

A.  Prints: 390

b)

B.  Prints: 195195

c)

C.  Prints: 195ab

d)

D.  Prints: ab195

21.

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)

A.  1

b)

B.  2

c)

C.  3

d)

D.  4

22.

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)

A.  Prints: A

b)

B.  Prints: B

c)

C.  Prints: C

d)

D.  Compile error

23.

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)

A.  Prints: ABC

b)

B.  Prints: ABCC

c)

C.  Prints: CBA

d)

D.  Prints: ABCBCC

24.

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)

A.  Prints: 0001

b)

B.  Prints: 012

c)

C.  Prints: 012012

d)

D.  Prints: 012345

25.

Which of the following is not primitive data type?

a)

A. byte

b)

B. short

c)

C. enum

d)

D. int

26.

Local variable which is?

a)

A. is declared inside the class but outside the method

b)

B. is declared inside the method

c)

C. All of the above