AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 1 - 9 of 9 questions

1

What is the result of compiling and running the following class. Select the one correct answer.



class Test {

   public void methodA(int i) {

      System.out.println(i); 

   }

   public int methodA(int i) {

      System.out.println(i+1); 

      return i+1; 

   }

   public static void main(String args[]) {

      Test X = new Test();

      X.methodA(5);

   }

}

 

a

The program compiles and runs printing 5

b

The program compiles and runs printing 6

c

The program gives runtime exception because it does not find the method Test.methodA(int)

d

The program give compilation error because methodA is defined twice in class Test

correct answer d
2

Which of the following are valid constructors within a class Test

a

test() { }

b

Test() { }

c

Test(void) { }

d

void Test() { }

correct answer b
3

Which of the following are legal declaration and definition of a method.

a

void method() {}

b

void method(void) {}

c

method(void) {}

d

void method {}

correct answer a
4

What will the result of compiling and executing the following program. Select the one correct answer.

class Test {

    public static void main(String args[]) {

	int arr[] = new int[2];

	System.out.println(arr[0]);

    }

}

 

a

The program does not compile because arr[0] is being read before being initialized

b

The program generates a runtime exception because arr[0] is being read before being initialized

c

The program compiles and prints 0 when executed

d

The program compiles and prints 1 when executed

correct answer c
5

Which of these array declarations and initializations are legal?

a

int arr[4] = new int[4];

b

int[4] arr = new int[4];

c

int arr[] = new int[4][4];

d

int[] arr = new int[4];

correct answer d
6

Which of these statements is illegal.

a

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

b

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

c

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

d

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

correct answer d
7

Given a one dimensional array arr, what is the correct way of getting the number of elements in arr. Select the one correct answer

a

arr.length

b

arr.size

c

arr.length()

d

arr.length() - 1

correct answer a
8

Which of the following is syntactically wrong ?

a

A. int a;

b

B. int 1b;

c

C. int _a;

d

D. None of the above

correct answer b

Identifier can begin with a letter, a currency character ($) or underscore (_).

9

Which of the following is syntactically correct ?

a

A. int d2;

b

B. int emp;

c

C. int $student;

d

D. All of the above

correct answer
Select a company to compare with

vs

Similar Companies