AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 1 - 10 of 150 questions

1

What happens when the following program is compiled and run. Select the one correct answer.


public class example {
   int i[] = {0};
   public static void main(String args[]) {
      int i[] = {1};
      change_i(i);
      System.out.println(i[0]);
   }
   public static void change_i(int i[]) {
      int j[] = {2};
      i = j;
   }
}

 

a

The program does not compile.

b

prints 0

c

prints 1

d

prints 2

correct answer c
2

What happens when the following program is compiled and run. Select the one correct answer.


public class example {
   int i[] = {0};
   public static void main(String args[]) {
      int i[] = {1};
      change_i(i);
      System.out.println(i[0]);
   }
   public static void change_i(int i[]) {
      i[0] = 2;
      i[0] *= 2;
   }
}

 

a

prints 0

b

prints 2

c

prints 4

d

prints 3

correct answer c
3

What happens when the following program is compiled and executed with the command - java test. Select the one correct answer.


class test {
   public static void main(String args[]) {
      if(args.length > 0)
         System.out.println(args.length);
   }
}

 

a

The program compiles and runs but does not print anything.

b

the program compiles and runs and prints 0

c

the program compiles and runs and prints 1

d

the program compiles and runs and prints 2

correct answer a
4

Which of these are valid declarations for the main method?

a

public void main();

b

public static void main(String args[]);

c

public static void main(String );

d

public static int main(String args[]);

correct answer b
5

What would be the results of compiling and running the following class. Select the one correct answer.


class test {
   public static void main() {
      System.out.println("test");
   }
}

 

a

The program does not compile as there is no main method defined.

b

The program compiles and runs generating an output of "test"

c

The program compiles and runs but does not generate any output.

d

The program compiles but does not run.

correct answer d
6

The initial value of an instance variable of type String that is not explicitly initialized in the program is --. Select the one correct answer

 

a

null

b

""

 

c

NULL

d

0

correct answer a,d
7

The initial value of an local variable of type String that is not explicitly initialized in the program is --. Select the one correct answer

 

a

null

b

""

 

c

NULL

d

The local variable must be explicitly assigned

correct answer a,d
8

What is the minimum value of char type. Select the one correct answer.

 

a

0

b

-215

c

-215 - 1

d

-216 - 1

correct answer a,d
9

How many bytes are used to represent the primitive data type int in Java.

 

a

2

b

4

c

8

d

1

correct answer b,d
10

What is the legal range of values for a variable declared as a byte

 

a

0 to 256

b

-128 to 127

c

-127 to 128

d

-215 to 215 - 1

correct answer b,d
Select a company to compare with

vs

Similar Companies