Java Programming Test

A Test to clear the basic programming concepts in Java

30 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following is a valid identifier?

  1. $identifier
  2. 2identifier
  3. ident*ifier
  4. identifier's
Question 2 Multiple Choice (Single Answer)

Which of the following options is not a keyword in JAVA?

  1. Extends
  2. Implements
  3. Throws
  4. Statics
Question 3 Multiple Choice (Single Answer)

Synchronized keyword can be applied to

  1. methods
  2. variables
  3. classes
  4. instance variables
Question 4 Multiple Choice (Single Answer)

What will be the output of the following code?

1 class AClass {2 String[] a;3 int[] numArray [] = {{1,2}, {1}};4 Object obj = new long[4];5 }

  1. Compilation succeeds
  2. Compilation fails due to an error in line 3
  3. Compilation fails due to an error in line 4
  4. Runtime error
Question 5 Multiple Choice (Single Answer)

Which of the following is not a valid constructor for the class HelloWorld?

  1. public HelloWorld(){}
  2. public void HelloWorld(){}
  3. private HelloWorld(){}
  4. protected HelloWorld(){}
Question 6 Multiple Choice (Single Answer)

Which of the following is the valid overridden method for public int sum(int a, int b){ }?

  1. public long sum(int a, int b){}
  2. public int sum(int a, int b){}
  3. public void sum(long a, long b){}
  4. public int sum(long a, long b){}
Question 7 Multiple Choice (Single Answer)

The term ____________ refers to the degree of one class using members of another class

  1. cohesion
  2. coupling
  3. polymorphism
  4. overloading
Question 8 Multiple Choice (Single Answer)

Mechanism underlying the concept of overriding is called

  1. encapsulation
  2. inheritance
  3. polymorphism
  4. transformation
Question 9 Multiple Choice (Single Answer)

An interface

  1. can implement only one interface
  2. can implement only two interfaces
  3. can implement multiple interfaces
  4. cannot implement any interface
Question 10 Multiple Choice (Single Answer)

How do you represent octal literal in JAVA?

  1. 0x67
  2. 67oct
  3. 067
  4. 67
Question 11 Multiple Choice (Single Answer)

What will be the output of the following?

public void test(){boolean x;if(x){System.out.println(false);}else{System.out.println(true);
}}

  1. Prints false
  2. Prints true
  3. Runtime error
  4. Compilation error
Question 12 Multiple Choice (Single Answer)

Which method is used for garbage collection?

  1. System.collectGarbage();
  2. System.gc();
  3. System.exit(0);
  4. System.garbage();
Question 13 Multiple Choice (Single Answer)

How do you find out the size of an array named intArray?

  1. intArray.length();
  2. intArray.size();
  3. intArray.length;
  4. intArray.size;
Question 14 Multiple Choice (Single Answer)

Which of the following is the logical XOR operator?

  1. &
  2. !
  3. |
  4. ^
Question 15 Multiple Choice (Single Answer)

If the test condition fails, the do-while loop will enter the loop body once.

  1. True
  2. False
  3. Can't say
  4. Either 1 or 2
Question 16 Multiple Choice (Single Answer)

What of the following is the output of the under given code?

public void sum(){ int a=10,b=2,c=3; if(b>a)&&(c>b){ c++; System.out.println(c=+c); } else{ c--; System.out.println(c=+c); }
}

  1. Prints c=3
  2. Prints c=4
  3. Prints c=2
  4. Compilation error
Question 17 Multiple Choice (Single Answer)

What is the output of the following code?

public void select(){int a = 2;switch(a){case 1: {System.out.println(case 1);}case 2: {System.out.println(case 2);}default: {System.out.println(default);}}}

  1. Prints case 1
  2. Prints case 2
  3. Prints case 2 default
  4. Prints case 1 case 2
Question 18 Multiple Choice (Single Answer)

Which method is used for converting a String to lowercase?

  1. lowercase();
  2. LowerCase();
  3. .toLowerCase();
  4. tolowercase();
Question 19 Multiple Choice (Single Answer)

What is the output of the following code?

public void concatenation(){String a = Hello;a.concat(World);System.out.println(a);}

  1. Prints case Hello World
  2. Prints case World
  3. Prints case Hello
  4. Prints case World Hello
Question 20 Multiple Choice (Single Answer)

A thread is considered dead when its __________ method completes.

  1. start()
  2. run()
  3. destroy()
  4. stop()
Question 21 Multiple Choice (Single Answer)

What is the output of the following?

public void test(){int x=0;if(x){System.out.println(false);}else{System.out.println(true);
}}

  1. Prints false
  2. Prints true
  3. Runtime error
  4. Compilation error
Question 22 Multiple Choice (Single Answer)

The default prioriy of a thread is

  1. 3
  2. 4
  3. 5
  4. 6
Question 23 Multiple Choice (Single Answer)

The situation where all threads wait for an exclusive lock on an object and none of the threads executes is called

  1. memory leak
  2. deadlock
  3. garbage collection
  4. encapsulation
Question 24 Multiple Choice (Single Answer)

The command used to invoke Java compiler is

  1. Java run
  2. Javacomp
  3. Javac
  4. Run Java
Question 25 Multiple Choice (Single Answer)

What is the output of the following code?public void test(){boolean x=false;if(x = true){System.out.println(false);}else{System.out.println(true);
}}

  1. Prints false
  2. Prints true
  3. Prints false true
  4. Prints true false
Question 26 Multiple Choice (Single Answer)

Exception thrown while trying to access an object at invalid index number, is

  1. ArrayIndexInvalidException
  2. ArrayIndexOutOfBoundsException
  3. ArrayIndexException
  4. ArrayIndexNullException
Question 27 Multiple Choice (Single Answer)

Arrays are indexed starting with

  1. 1
  2. 0
  3. -1
  4. 2
Question 28 Multiple Choice (Single Answer)

How do you instantiate the under given inner class?

class OuterClass { public void makeInner() { InnerClass in = new InnerClass(); // make an inner instance} class InnerClass { public void test() { System.out.println(Hello World); } }}

  1. OuterClass outer = new OuterClass();OuterClass.InnerClass inner = outer.new InnerClass();
  2. InnerClass inner = OuterClass.new InnerClass();
  3. OuterClass outer = new OuterClass();InnerClass inner = outer.new InnerClass();
  4. InnerClass inner = new InnerClass();
Question 29 Multiple Choice (Single Answer)

Which of the following options is given default value?

  1. Local variables
  2. Automatic variables
  3. Instance variables
  4. None of these
Question 30 Multiple Choice (Single Answer)

What is the output of the following code?

public void select(){int a = 2;switch(a){Case 1: {System.out.println(case 1);}Case 2: {System.out.println(case 2);}Case 2: {System.out.println(case 2 repeated);}default: {System.out.println(default);}}}

  1. Prints case 1
  2. Compilation error
  3. Prints case 2 repeated
  4. Prints case 1 case 2