Java Programming Test
A Test to clear the basic programming concepts in Java
Questions
Which of the following is a valid identifier?
- $identifier
- 2identifier
- ident*ifier
- identifier's
Which of the following options is not a keyword in JAVA?
- Extends
- Implements
- Throws
- Statics
Synchronized keyword can be applied to
- methods
- variables
- classes
- instance variables
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 }
- Compilation succeeds
- Compilation fails due to an error in line 3
- Compilation fails due to an error in line 4
- Runtime error
Which of the following is not a valid constructor for the class HelloWorld?
- public HelloWorld(){}
- public void HelloWorld(){}
- private HelloWorld(){}
- protected HelloWorld(){}
Which of the following is the valid overridden method for public int sum(int a, int b){ }?
- public long sum(int a, int b){}
- public int sum(int a, int b){}
- public void sum(long a, long b){}
- public int sum(long a, long b){}
The term ____________ refers to the degree of one class using members of another class
- cohesion
- coupling
- polymorphism
- overloading
Mechanism underlying the concept of overriding is called
- encapsulation
- inheritance
- polymorphism
- transformation
An interface
- can implement only one interface
- can implement only two interfaces
- can implement multiple interfaces
- cannot implement any interface
How do you represent octal literal in JAVA?
- 0x67
- 67oct
- 067
- 67
What will be the output of the following?
public void test(){boolean x;if(x){System.out.println(false);}else{System.out.println(true);
}}
- Prints false
- Prints true
- Runtime error
- Compilation error
Which method is used for garbage collection?
- System.collectGarbage();
- System.gc();
- System.exit(0);
- System.garbage();
How do you find out the size of an array named intArray?
- intArray.length();
- intArray.size();
- intArray.length;
- intArray.size;
Which of the following is the logical XOR operator?
- &
- !
- |
- ^
If the test condition fails, the do-while loop will enter the loop body once.
- True
- False
- Can't say
- Either 1 or 2
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); }
}
- Prints c=3
- Prints c=4
- Prints c=2
- Compilation error
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);}}}
- Prints case 1
- Prints case 2
- Prints case 2 default
- Prints case 1 case 2
Which method is used for converting a String to lowercase?
- lowercase();
- LowerCase();
- .toLowerCase();
- tolowercase();
What is the output of the following code?
public void concatenation(){String a = Hello;a.concat(World);System.out.println(a);}
- Prints case Hello World
- Prints case World
- Prints case Hello
- Prints case World Hello
A thread is considered dead when its __________ method completes.
- start()
- run()
- destroy()
- stop()
What is the output of the following?
public void test(){int x=0;if(x){System.out.println(false);}else{System.out.println(true);
}}
- Prints false
- Prints true
- Runtime error
- Compilation error
The default prioriy of a thread is
- 3
- 4
- 5
- 6
The situation where all threads wait for an exclusive lock on an object and none of the threads executes is called
- memory leak
- deadlock
- garbage collection
- encapsulation
The command used to invoke Java compiler is
- Java run
- Javacomp
- Javac
- Run Java
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);
}}
- Prints false
- Prints true
- Prints false true
- Prints true false
Exception thrown while trying to access an object at invalid index number, is
- ArrayIndexInvalidException
- ArrayIndexOutOfBoundsException
- ArrayIndexException
- ArrayIndexNullException
Arrays are indexed starting with
- 1
- 0
- -1
- 2
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); } }}
- OuterClass outer = new OuterClass();OuterClass.InnerClass inner = outer.new InnerClass();
- InnerClass inner = OuterClass.new InnerClass();
- OuterClass outer = new OuterClass();InnerClass inner = outer.new InnerClass();
- InnerClass inner = new InnerClass();
Which of the following options is given default value?
- Local variables
- Automatic variables
- Instance variables
- None of these
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);}}}
- Prints case 1
- Compilation error
- Prints case 2 repeated
- Prints case 1 case 2