0

programming languages Online Quiz - 323

Description: programming languages Online Quiz - 323
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

What is the output of the following code when compiled and run? Select one correct answer. public class Question02 { public static void main(String[] args){ int j = 017; int i = (byte)j >> 2; //line 1 System.out.println(Integer.toBinaryString(i)); //line 2 } }

  1. Prints 3

  2. Error during compilation at line 1

  3. Prints 11

  4. Prints 0


Correct Option: C

What is the output of the following code when compiled and run? Select one correct answer. import java.io.*; public class Question05 { public static void main(String[] args) { Question05Sub myref = new Question05Sub(); try{ myref.test(); }catch(IOException ioe){} } void test() throws IOException{ System.out.println("In Question05"); throw new IOException(); } } class Question05Sub extends Question05 { void test() { System.out.println("In Question05Sub"); } }

  1. Prints: In Question05Sub

  2. Prints: In Question05

  3. Prints:In Question05In Question05Sub

  4. The code does not compile.


Correct Option: D

What is the output of the following code when compiled and run? Select one correct answer. public class Question41{ public static void main(String[] args){ Object[] obj = new Object[3]; for(int i=0;i

  1. Compilation error.

  2. Prints: 1 3 4 true false true

  3. Prints: 1 2 4 false false true

  4. Prints: 3 4 true true true

  5. None of the above.


Correct Option: C

When an instance of a class, or object, is specified as a parameter to a method, a reference to the said object is passed to the method.

  1. True

  2. False


Correct Option: A

All interface methods must be declared as public when implemented in a class.

  1. True

  2. False


Correct Option: A

A method in a class declared as static may be invoked simply by using the name of the method alone.

  1. True

  2. False


Correct Option: B

A static method can refer to any instance variable of the class.

  1. True

  2. False


Correct Option: B

Each method in a class must have a unique name.

  1. True

  2. False


Correct Option: B
  1. Given a one dimensional array arr, what is the correct way of getting the number of elements in arr. Select the one correct answer.
  1. a. arr.length

  2. b. arr.length - 1

  3. c. arr.size

  4. d. arr.size - 1

  5. e. arr.length()


Correct Option: A
  1. Which of these statements are legal. Select the three correct answers.
  1. a. int arr[][] = new int[5][5];

  2. b. int []arr[] = new int[5][5];

  3. c. int[][] arr = new int[5][5];

  4. d. int[] arr = new int[5][];

  5. e. int[] arr = new int[][5];


Correct Option: A,B
  1. Select all correct declarations, or declaration and initializations of an array?
  1. a. String str[];

  2. b. String str[5] = new String[5];

  3. c. String str[] = new String[] {"string1", "string2", "string3", "string4", "string5

  4. d. String str[] = {"string1","string2", "string3", "string4", "string5"};


Correct Option: A,C,D

6 What will happen when you compile the following code? 1. package sources; 2. public class firstjava { 3. public static void main(String args[]) 4. { 5. private int a[] ={ 4, 4 }; 6. public int b=1; 7. a[b]=b=0; 8. System.out.println("value of b & a[0] & a[1]" + b + a[0] +a[1]); 9. } 10. }

    1. Compilation error at line 2
    1. Runtime error at line 7.
    1. Compilation error at Line 7
    1. Compiles and prints 0 0 4
    1. Compiles and prints 0 4 0

Correct Option: A

11 What will the following code print out? public class Oct{ public static void main(String argv[]){ Oct o = new Oct(); o.amethod(); } public void amethod(){ int oi= 012; System.out.println(oi); } }

  1. A 12

  2. B 012

  3. C 10

  4. D 10.0


Correct Option: C
- Hide questions