0
Alien head

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

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

10 What modifiers would be legal at XX in the following code? public class MyClass1 { public static void main(String argv[]){ } /*Modifier at XX */ class MyInner {} }

  1. a. public

  2. b. private

  3. c. static

  4. d. friend


Correct Option: A,B

9 If you run the code below, what gets printed out? String s=new String("Bicycle"); int iBegin=1; char iEnd=3; System.out.println(s.substring(iBegin,iEnd));

  1. a. Bic

  2. b. ic

  3. c. icy

  4. d. error: no method matching substring(int,char)


Correct Option: B

8 What will happen if you attempt to compile and run the following code? Integer ten=new Integer(10); Long nine=new Long (9); System.out.println(ten + nine); int i=1; System.out.println(i + ten);

  1. a. 19 followed by 20

  2. b. 19 followed by 11

  3. c. Compile time error

  4. d. 10 followed by 1


Correct Option: A

7 What will be the result of attempting to compile and run the following code? abstract class MineBase { abstract void amethod(); static int i; } public class Mine extends MineBase { public static void main(String argv[]){ int[] ar=new int[5]; for(i=0;i < ar.length;i++) System.out.println(ar[i]); } }

    1. a sequence of 5 0's will be printed
    1. Error: ar is used before it is initialized
    1. Error Mine must be declared abstract
    1. IndexOutOfBoundes Error

Correct Option: C

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

5 What will be printed when you execute the code? class A { A() { System.out.println("Class A Constructor"); } } public class B extends A { B() { System.out.println("Class B Constructor"); } public static void main(String args[]) { B b = new B(); } }

    1. Class A Constructor followed by Class B Constructor
    1. Class B Constructor followed by Class A Constructor
    1. Compile time error
    1. Run time error

Correct Option: A

4 Which of the following are the java keywords?

    1. final
    1. Abstract
    1. Long
    1. static

Correct Option: A,D
  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
  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. 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

Each method in a class must have a unique name.

  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

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

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

  1. True

  2. False


Correct Option: A

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

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

Select three correct statements about the following code. public class Question20 { public static void main(String[] args) { Question20 myref = new Question20Sub(); try{ myref.test(); }catch(Exception e){} } void test() throws Exception{ System.out.println("In Question20"); throw new Exception(); } } class Question20Sub extends Question20 { void test() { System.out.println("In Question20Sub"); } }

  1. The try-catch block that encloses myref.test(); is mandatory for the code to compile.

  2. Prints: In Question20

  3. Prints: In Question20Sub

  4. Method test() in class Question20Sub has no obligation to declare a throws clause.

  5. An exception is thrown at runtime.


Correct Option: A,C,D

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 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
+ View questions