Monday, June 11, 2018

15 Simple But Confusing Java Interview


15 Simple But Confusing Java Interview 


1) Are true and false keywords in java.?
No, true and false are not keywords in java. They are literals in java. You can not use them as identifiers in your program. They are reserved words in java.
2) Can we declare local inner class as private.?
No, local inner class can not be declared as private or protected or public.
3) Is “abc” a primitive value.?
No, “abc” is not a primitive value. It is a string object.
4) Is an exception occurred in one thread causes other threads to terminate.?
No, exception is thread wise. Only that thread will terminate in which exception has occurred. Other threads will continue to execute.
5) Can array size be negative.?
No, array size can not be negative. If you specify array size as negative, there will be no compile time error, but you will get NegativeArraySizeException at run time.
6) If class A and class B are two sub classes of class C, then can a reference variable of Class A type refer to  an object of class B type or Vice versa.?
No. Class A  type reference variable can not refer to class B type object or class B type reference variable can not refer to class A type object.
7) What is the priority of Garbage Collector thread. is it low or high.?
Garbage Collector thread is a low priority thread.
8) Is an object garbage collected even after an exception is occurred in the program.?
Yes, Garbage collector ignores any exceptions occurred in the program.
9) Is Map of Collection type.?
No, Map is not a Collection type. Even though Map is included in the collection framework, it does not inherit from Collection interface.
10) Can we define sub class first and super class later in a java file.?
Yes, Order of sub class and super class does not matter.
11) Which package is always imported by default.?
java.lang package is always imported by default.
12) Can a class implement two interfaces having same method.?
Yes, a class can implement two interfaces having same method but that method should be implemented only once ( or can be overloaded ) in the class.
13) Which one will be faster?
a) for(int i = 0; i < 1000; i++) {}
b) for(int i = 1000; i > 0; i–) {}
b) for(int i = 1000; i > 0; i–) {} will be faster.
14) Can we declare interface methods as static.?
No, we can’t declare interface methods as static.
15) Which one is faster among String, StringBuffer and StringBuilder.?
StringBuilder.

No comments:

Post a Comment