Interview Questions and Answers for 'Oop' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

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.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   next 30
 Q71. Can we declare an abstract method private ?
Ans. No Abstract methods can only be declared protected or public.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   abstract   oops   access specifier   private   yes-no      intermediate        rare


 Q72. What are the design considerations while making a choice between using interface and abstract class ?Core Java
Ans. Keep it as a Abstract Class if its a "Is a" Relationsship and should do subset/all of the functionality. Keep it as Interface if its a "Should Do" relationship.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   abstract classes   interfaces   advanced     Asked in 3 Companies


 Q73. Can we call constructor explicitly ?
Ans. Yes.

 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   yes-no

Try 1 Question(s) Test


 Q74. Does a class inherit the constructor of its super class?
Ans. No.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   constructor   inheritence   constructor inheritance   yes no


 Q75. What are the features of encapsulation ?Core Java
Ans. Combine the data of our application and its manipulation at one place.

Encapsulation Allow the state of an object to be accessed and modified through behaviors.

Reduce the coupling of modules and increase the cohesion inside them.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   oops concepts   encapsulation  object oriented programming (oops)  oops concepts   basic interview question     Asked in 2 Companies      basic        frequent


 Q76. Difference between new operator and Class.forName().newInstance() ?
Ans. new operator is used to statically create an instance of object. newInstance() is used to create an object dynamically ( like if the class name needs to be picked from configuration file ). If you know what class needs to be initialized , new is the optimized way of instantiating Class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   object instantiation   object creation   class.forname   newinstance   new operator   difference between   advanced      intermediate


 Q77. What are the considerations to be made in case of loops in Java ?Core Java
Ans. 1. It shouldn't result in infinite loop. Please make sure that you have a condition that will terminate the loop and that condition should be reached.

2. Make sure to use the break statement if you aspire to only look for something. Not using break will unnecessarily execute it till the end of for loop in some cases.

3. Similarly use continue to execute the loop with next iteration and bypass the rest of the code block if required.

4. Try to avoid multiple nesting of for loops. If it''s required, Make sure to use break and continue properly so as to avoid some unnecessary processing.

5. Make sure to use try catch within the loop and not outside the for loop if you expect it to continue if one of the iteration fails.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   loops   continue   break   for loop  control statements  loop statement.while loop  control statements  loop statement   architecture


 Q78. How is Abstraction implemented in Java ?Core Java
Ans. Abstraction is provided in Java by following ways -

Coding to the ( Interfaces / Abstract Classes ) or contracts

By Encapsulating details within classes and exposing the minimal Door ( few public methods )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops concepts   abstraction   interfaces   abstract class   encapsulation  object oriented programming (oops)  oops concepts     Asked in 3 Companies      basic        frequent


 Q79. Which of the following cannot be marked static ?

a. Constructors , Classes ( Outer ) , Classes ( nested ), Interfaces , Local variables , Inner Class methods and instance variables.
b. Constructors , Classes ( Outer ) , Interfaces , Local variables , Class variables , Class Methods , Inner Class methods and instance variables.
c. Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables.
d. Constructors , Classes ( Outer ) , Classes (Nested), Interfaces , Local variables , Inner Class methods and instance variables
Ans. Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     oops   java   static   nested classes   static nested classes

Try 2 Question(s) Test


 Q80. Interface can only have ...

a. Member elements and Methods.
b. Static Variables and Static Methods.
c. Static Final Variables and Instance Method Declarations.
d. Member Elements , Instance Methods, Static variables and Static Methods.
Ans. Static Final Variables and Instance Method Declarations.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   interfaces


 Q81. If everything is an object , Cant we declare every object as

Object obj = new String();
Core Java
Ans. Yes, we can do that. Compiler wont complain. But using object reference we can only access methods which have been defined for object class i.e clone(), equals(), hashCode(), toString() etc.

We cannot access methods defined in String class or in any class in hierarchy between String and Object.

For example - we cannot do obj.append("abc") as it will now give compile time error.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     object initialization  object declaration   runtime polymorphism  object oriented programming (oops)  oops concepts


 Q82. What is the difference between for and foreach loop in java ? Which one should be used in which cases ?

Core Java
Ans. 1. for loop in java is used with a counter as following

for(int counter=0;counter < 50;counter++){
System.out.println(list.get(counter));
}

for iterating and printing the contents of a collection

whereas foreach loop can be specified directly without the use of counter

for(String str:list){
System.out.println(list.get(counter));
}

2. for Each loop syntax is more clean if we have to iterate over the elements of a collection and we need not keep track of the record count

3. For is preferred when we need loops without the usage of collections or Array of objects and entirely primitives are being used

4. for loop is preferred if we need to keep track of record count and have to perform some action of the basis of that. For example - If we have to print something after every 5 records, With for each loop in such case, we will have to keep a separate counter.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     loop  for loop  control statements  loop statement  foreach loop  for vs foreach loop


 Q83. How does java identifies which method to be called in method overriding or runtime polymorphism, when both methods share the same name and signature ? Core Java
Ans. Java identifies the method to be called at runtime by the object that is being referenced.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     polymorphism  object oriented programming (oops)  oops concepts  overloading  overriding      basic


 Q84. What is abstraction ?Design
Ans. Abstraction is a process of hiding the implementation details and describing only the functionality to the user.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     bstraction  oops concepts  oops principle     Asked in 22 Companies


 Q85. Can we have multiple inheritance in java using abstract class ?Core Java
Ans. No

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     abstract class   multiple inheritance  object oriented programming (oops)  oops concepts     Asked in 2 Companies


 Q86. Does use of Final class enforces composition over Inheritance in Java ? Core Java
Ans. Yes, to a certain extent. But the objective for Final class could be beyond just enforcing composition as certain classes might have been created without inheritance or composition in mind.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     final class   composition  object oriented programming (oops)  oops concepts  inheritance  object oriented programming (oops)  oops concepts  composition  object oriented programming (oops)  oops concepts vs inheritance  object oriented programming (oops)  oops concepts      expert


 Q87. What could be the reasons for restricting inheritance using final class ?Core Java
Ans. 1. Enforcing composition over inheritance
2. Restricting overriding of certain methods
3. Final methods are faster than regular instance methods
4. Enforcing Immutability

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     final class   reasons for final class   restricting inheritance  object oriented programming (oops)  oops concepts      expert


 Q88. What is cyclic instantiation ? Have you ever faced any problem due to this ?OOP
Ans. Cyclic instantiation in OOPs may happen if Class A loading results in Class B Loading , and then Class B Loading results in Class C loading and then Class C has a static reference to Class A and hence results in cyclic instantiation or loading.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q89. Why cannot we initialize a final field within the constructor if the initialization is within try block ?Core Java
Ans. What if the initialization throws an exception. In that case , it will let it move forward without initializing the final field. So it's a way to enforce that either the field is initialized or it fails completely.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     oops


 Q90. Can we reduce the visibility of the overridden method ?Core Java
Ans. No

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     overriding   access specifier   oops   java   yes-no


 Q91. Can static method access instance variables ?Core Java
Ans. Though Static methods cannot access the instance variables directly, They can access them using instance handler.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     static   static method   java   oop   variables     Asked in 1 Companies      basic        frequent


 Q92. Does java allow overriding static methods ?Core Java
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.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   static   static method   overriding      intermediate

Try 3 Question(s) Test


 Q93. Why java doesn't support multiple Inheritence ?Core Java
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     java   oops   inheritence   multiple inheritence     Asked in 1 Companies      basic        frequent


 Q94. What restrictions are placed on method overriding?
Ans. Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   overriding      basic        frequent

Try 2 Question(s) Test


  Q95. Explain static blocks in Java ?Core Java
Ans. A static initialization block is a normal block of code enclosed in braces, { }, and preceded by the static keyword. Here is an example:

static {
// whatever code is needed for initialization goes here
}

A class can have any number of static initialization blocks, and they can appear anywhere in the class body. The runtime system guarantees that static initialization blocks are called in the order that they appear in the source code.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   static   static block     Asked in 16 Companies      basic        frequent


 Q96. Explain use of nested or inner classes ?Core Java
Ans. Sometime we just need classes or class objects just to be used as part of a particular class or objects. Making them non nested won't make any difference as far as functionality is concerner but making them Nested provide a level of convenience and protection fro, being used anywhere else. Moreover it helps reducing the Code.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   inner classes   nested class   inner class     Asked in 2 Companies

Try 1 Question(s) Test


 Q97. What is a finalize method ?Core Java
Ans. finalize() method is called just before an object is destroyed.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   finalize   garbage collection   basic interview question     Asked in 1 Companies      basic        frequent

Try 1 Question(s) Test


 Q98. Is runnable a Marker interface ?Core Java
Ans. No , it has run method declared.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   interfaces   marker interface   runnable   yes-no


Recently asked in Infoview Technologies.
 Q99. What is a Default Constructor ?Core Java
Ans. The no argument constructor provided by Java Compiler if no constructor is specified.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   constructor   default constructor     Asked in 1 Companies      Basic        frequent

Try 2 Question(s) Test


 Q100. Will Compiler creates a default no argument constructor if we specify only multi argument constructor ?
Ans. No, Compiler will create default constructor only if we don't specify any constructor.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   constructor   default constructor   yes-no      expert        rare

Try 1 Question(s) Test


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: