Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers - Order By Newest | ||||
| ||||
Ans. Though It's often confused with each other, Object Creation ( Instantiation ) and Initialization ( Construction ) are different things in Java. Construction follows object creation. Object Creation is the process to create the object in memory and returning its handler. Java provides New keyword for object creation. Initialization is the process of setting the initial / default values to the members. Constructor is used for this purpose. If we don't provide any constructor, Java provides one default implementation to set the default values according to the member data types. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   constructor   object instantiation | ||||
Frequently asked to fresh graduates and less experienced. | ||||
| ||||
Ans. Inheritance. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  inheritance  object oriented programming (oops)  oops concepts   java   oops   composition  object oriented programming (oops)  oops concepts Asked in 1 Companies basic   frequent | ||||
Very frequently asked in phone and walk in interviews. | ||||
| ||||
Ans. An interface without any method declaration is called as marker interface. there are 3 in-built interfaces in JVM i.e. serializable, clonable, remote | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   interfaces   marker interface   serializable   clonable Asked in 21 Companies intermediate   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. With Java 9 we can declare interface methods as private | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   interfaces   yes-no   private | ||||
| ||||
Ans. We can do so through a static public member method or static block. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   static   constructor   static method   static block  private Asked in 1 Companies | ||||
| ||||
Ans. As we only downcast class in the hierarchy, The ClassCastException is thrown to indicate that code has attempted to cast an object to a subclass of which it is not an instance. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   class casting   classcastexception   exception   error Asked in 4 Companies intermediate   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. 1.this is a reference to the current object in which this keyword is used whereas super is a reference used to access members specific to the parent Class. 2.this is primarily used for accessing member variables if local variables have same name, for constructor chaining and for passing itself to some method whereas super is primarily used to initialize base class members within derived class constructor. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   class   objects   inheritence   constructor   this   super   this vs super Asked in 1 Companies | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. Both belong to the class as a whole and not to the individual objects. Static methods are explicitly called for execution whereas Static block gets executed when the Class gets loaded by the JVM. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   static   static method   static block   difference between   similarity basic   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. A child object constructor always first needs to construct its parent. In Java it is done via an implicit call to the no-args constructor as the first statement | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   constructor   constructor chaining   oops   call constructor explicitly Asked in 3 Companies | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. At the beginning of an object's life, the Java virtual machine (JVM) allocates memory on the heap to accommodate the object's instance variables. When that memory is first allocated, however, the data it contains is unpredictable. If the memory were used as is, the behavior of the object would also be unpredictable. To guard against such a scenario, Java makes certain that memory is initialized, at least to predictable default values before it is used by any code. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   constructor   oops   default constructor   jvm expert | ||||
Try 2 Question(s) Test | ||||
Ans. No the static block won't get executed as the referenced variable in the Test class is final. Compiler replaces the content of the final variable within Demo.main method and hence actually no reference to Test class is made. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   static   static block   final variable | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. A no argument constructor is provided by the compiler if we declare only constructors with arguments. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   constructor | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. class A { void test() { System.out.println("test() method"); } } class B { void test() { System.out.println("test() method"); } } Suppose if Java allows multiple inheritance like this, class C extends A, B { } A and B test() methods are inheriting to C class. So which test() method C class will take? As A & B class test() methods are different , So here we would Facing Ambiguity. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  multiple inheritance  object oriented programming (oops)  oops concepts  diamond problem Asked in 20 Companies basic   frequent | ||||
| ||||
Ans. A Method that cannot be overriden in the sub class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   java keywords   final   final method   overriding   basic interview question basic   frequent | ||||
Try 1 Question(s) Test | ||||
Very Frequently asked.Favorite question in Walk in drive for many Indian service companies. | ||||
| ||||
Ans. A Class that cannot be sub classed. | ||||
Sample Code for final class | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   final   final class   java keyword   basic interview question Asked in 3 Companies basic   frequent | ||||
Very frequently asked. Usually asked with questions related to String. Frequently asked at CTS / Cognizant | ||||
| ||||
Ans. Object that can't be changed after instantiation. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   immutable  immutability Asked in 27 Companies basic   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Only declaring variables as final makes them immutable. Making objects final means that the object handler cannot be used to target some other object but the object is still mutable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   final   immutable  immutability   immutable  immutability object | ||||
| ||||
Ans. No. Static methods belong to the class and not the objects. They belong to the class and hence doesn't fit properly for the polymorphic behavior. A static method is not associated with any instance of a class so the concept of overriding for runtime polymorphism using static methods is not applicable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   static   static methods   java keywords   yes-no intermediate   frequent | ||||
| ||||
Ans. No. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   access specifier   overriding   overridding   inheritence   yes-no | ||||
| ||||
Ans. IndexOutofBoundException , NoClassDefFoundException , OutOfMemoryException , IllegalArgumentException, NullPointerException, IllegalStateException | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   exceptions   basic interview question basic   frequent | ||||
| ||||
Ans. By putting it within finally. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   exceptions   finally   uncatched exceptions basic   frequent | ||||
| ||||
Ans. Used to access members of the base class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   java keywords   super   basic interview question Asked in 2 Companies basic   frequent | ||||
| ||||
Ans. Used to represent an instance of the class in which it appears. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   java keywords   this   basic interview question basic   frequent | ||||
| ||||
Ans. boolean is a primitive type whereas Boolean is a class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   wrapper classes   boolean vs Boolean basic   rare | ||||
| ||||
Ans. Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   serialization   deserialization   serialization vs deserialization Asked in 2 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. Inner class is a type of nested class. Inner classes are non static nested classes i.e the one that are associated with the instance of outer class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   static   nested classes   inner classes   nested vs inner class basic   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. Any interface declared inside a class or an interface. It is static by default. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   nested classes | ||||
| ||||
Ans. Externalizable interface is used to write the state of an object into a byte stream in compressed format. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   serialization   externalizable interface   interface Asked in 3 Companies | ||||
| ||||
Ans. Serializable is a marker interface whereas externalizable is not. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   serialization   externalizable   interface   marker interface | ||||
| ||||
Ans. Yes, as protected constructor is accessible in sub class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   constructor   access specifier   protected   yes-no  private constructor | ||||