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 Rating

   next 30
 Q31. What is the difference between return and continue statement ?Core Java
Ans. return is used within a method to return control out of the method. It may be followed by a value which is returned from the method to calling method immediately preceding the point of call.

continue statement is used within a loop to start next iteration without executing the remaining statements in the loop.

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

   Like         Discuss         Correct / Improve     return statement  continue statement  return vs continue  for loop  control statements  loop statement


 Q32. Explain Inheritance and Polymorphism.Core Java
Ans. Getting parent class object properties into child class is called Inheritance.

The process of representing one form into multiple forms is called polymorphism.

 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  polymorphism  object oriented programming (oops)  oops concepts     Asked in 1 Companies      Basic        frequent


 Q33. What is an infinite loop ?Core Java
Ans. Infinite loop is a programming condition wherein the control goes into an infinite loop because the loop termination condition can never be met. For example -

for(int x=1;x>0;x++){
}

in this loop, with each increment the condition x > 0 will remain true till infinity.

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

   Like         Discuss         Correct / Improve     loop  infinite loop  for loop  control statements  loop statement      basic


 Q34. What are the different types of loops in Java ?Core Java
Ans. for, while and do while

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

   Like         Discuss         Correct / Improve     loops  different type of loops  for loop  control statements  loop statement      basic


 Q35. Give an example of how Object Oriented Programming Concepts can be implemented.Design
Ans. You can implement encapsulation in Java by keeping the fields (class variables) private and providing public getter and setter methods to each of them. Java Beans are examples of fully encapsulated classes. Encapsulation in Java: Restricts direct access to data members (fields) of a class.

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

   Like         Discuss         Correct / Improve     oops  oops example  oops concepts  oops features     Asked in 2 Companies      basic        frequent


  Q36. Explain OOPs

or

Explain OOPs Principles

or

Explain OOPs Concepts

or

Explain OOPs features

or

Tell me something about OOPs
Core Java
Ans. OOPs or Object Oriented Programming is a Programming model which is organized around Objects instead of processes. Instead of a process calling series of processes, this model stresses on communication between objects. Objects that all self sustained, provide security by encapsulating it's members and providing abstracted interfaces over the functions it performs. OOP's facilitate the following features

1. Inheritance for Code Reuse
2. Abstraction for modularity, maintenance and agility
3. Encapsulation for security and protection
4. Polymorphism for flexibility and interfacing

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

   Like         Discuss         Correct / Improve     oops  oops features     Asked in 260 Companies      basic        frequent


Very frequently asked. Usually among very first few questions.
 Q37. Define encapsulation in Java ?Core Java
Ans. Encapsulation is a feature of OOP's that binds the data and it's associated methods together as a single unit and facilitate protection and data hiding by providing minimal interface to outside. For example - member variables are declared private and are accessed through public methods. Moreover we have private methods that can only be used internally and hence providing minimal interface to outside class through use of public methods.

  Sample Code for encapsulation

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

   Like         Discuss         Correct / Improve     encapsulation  object oriented programming (oops)  oops concepts  oops  oops concepts  oops features     Asked in 4 Companies      Basic        frequent


 Q38. How can we hide a class in Java ?Core Java
Ans. By encapsulating it within another class and declaring it private. In such a case, it will only be accessible through parent class or parent class object.

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

   Like         Discuss         Correct / Improve     private class   private inner class  class hiding  encapsulation  object oriented programming (oops)  oops concepts  inner classes   nested classes


 Q39. What happens to private variables during inheritance ?Core Java
Ans. Private variables are not inherited. They are simply ignored and not made part of the derived object body.

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

   Like         Discuss         Correct / Improve     private variables  inheritance  object oriented programming (oops)  oops concepts


 Q40. What is dynamic dispatch in Java ?Core Java
Ans. Dynamic dispatch in java is also known as runtime polymorphism.It is a process in which a call to an overriden method is resolved at runtime.

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

   Like         Discuss         Correct / Improve     dynamic dispatch  runtime polymorphism  object oriented programming (oops)  oops concepts


 Q41. How do you take screenshot in selenium?Selenium
Ans. TakeScreenshot th = TakeScreenshot(driver); //Enable the driver object to take screenshot

File src = th.getScreenShotAs(OutputType.FILE);

FileUtils.copyFilesrc("locationWhereUWantToPlaceTheScreenshot.jpg");

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

   Like         Discuss         Correct / Improve     webdriver  selenium     Asked in 1 Companies


 Q42. What is "dynamic method dispatch" in java ?Core Java
Ans. dynamic method dispatch is a process in which a call to an
overridden method is resolved at runtime rather than at compile-time. This is used to achieve runtime polymorphism in java.

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

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


 Q43. 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


 Q44. Which of the two - compile time and run time polymorphism - requires signature of the method to be different ?Core Java
Ans. runtime polymorphism or method overriding doesn't require method name and signature to be different whereas compile time polymorphism or method overloading requires method name to be same but the signature to be different.

 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


 Q45. What are the counter controlled repetitions in java ? Core Java
Ans. Counter controlled repetitions are the loops that are controlled with the use of counters or the loops where the number of repetitions are known in advance. for loop in java is the counter controlled repetition.

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

   Like         Discuss         Correct / Improve     for loop  control statements  loop statement


 Q46. Is it a good design practice to have programming constructs like if and loops in constructor ?Design
Ans. I would avoid that. If we need to initialize member elements differently on the basis of some condition, I would prefer having overloaded constructors. I don't see a need to have a loop for initializing member elements unless the count of elements is huge and they all need to be initialized with common value.

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

   Like         Discuss         Correct / Improve     design constructor  for loop


 Q47. how many reducer task runs on a hadoop cluster ?BigData
Ans. Generally one reducer runs for all mappers, but it can be increased as per requirements.

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

   Like         Discuss         Correct / Improve     Hadoop  BigData     Asked in 1 Companies


 Q48. How are the concept of Association related to Composition and Inheritance ?Core Java
Ans. Composition and Inheritance are the different types of Associations for Classes.

Composition is a has-a association between classes.
Inheritance is a is-a association between classes.

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

   Like         Discuss         Correct / Improve     composition  object oriented programming (oops)  oops concepts  inheritance  object oriented programming (oops)  oops concepts  association  relationship between objects


  Q49. What are the core OOPs concepts ?Core Java
Ans. Abstraction, Encapsulation, Polymorphism , Composition and Inheritance

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

   Like         Discuss         Correct / Improve     core oops concepts     Asked in 65 Companies      basic        frequent


 Q50. Can you name some of the Java frameworks in different domains ?Frameworks
Ans. Web Framework - Spring , Struts, Play
Dependency Injection frameworks - Google Guice , PicoContainer and Dagger
ORM Framework - Hibernate
Big Data / ETL Frameworks - Apche Hadoop , Apache Crunch, Apache Spark.
View Frameworks - JSF , Apache Wicket,jtwig.
Java Gui Frameworks - SWT , AWT, JavaFX
Testing - Junit, Mockito, PowerMock, EasyMock, JMock, JMockit
Rest Web services - Jersey , Restlet , RestX, RestEasy ,Restfulie

Here is the big list for reference - http://javasearch.buggybread.com/home2.php?keyword=

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

   Like         Discuss         Correct / Improve     frameworks     Asked in 2 Companies      intermediate        frequent


  Q51. Why java doesn't support multiple Inheritance ?

or

Explain Java Diamond Problem.
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     multiple inheritance  object oriented programming (oops)  oops concepts  diamond problem     Asked in 20 Companies      basic        frequent


 Q52. 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


 Q53. 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


Basic and Very Frequently asked.
  Q54. What is Polymorphism in Java ?Core Java
Ans. Polymorphism means the condition of occurring in several different forms.

Polymorphism in Java is achieved in two manners

1. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas

2. Dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding.

  Sample Code for overloading

  Sample Code for overriding

 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  oops concepts     Asked in 108 Companies      Basic        frequent

Try 2 Question(s) Test


Very Frequently asked to fresh graduates and less experienced.
 Q55. What are the principle concepts of Object Oriented Programming ?Core Java
Ans. Abstraction Polymorphism Inheritance Encapsulation

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

   Like         Discuss         Correct / Improve     oops  oops concepts     Asked in 1 Companies      basic        frequent


 Q56. What is the use of Combiners ?BigData
Ans. Combiners are used to increase the efficiency of a Map Reduce program. They are used to aggregate intermediate map output locally on individual mapper outputs. Combiners can help you reduce the amount of data that needs to be transferred across to the reducers.

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

   Like         Discuss         Correct / Improve     Hadoop Systems  BigData   hadoop combiners     Asked in 1 Companies


 Q57. What is Hadoop Framework ?BigData
Ans. Hadoop is an open source framework , written in java by apche software foundation. This framework is used to write applications to process vast amount of data. Processing happens in parallel on large clusters which could have 1000 of computers. It processes data in a very reliable and fault tolerant manner.

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

   Like         Discuss         Correct / Improve     Hadoop framework  BigData


 Q58. What are the two main components of Hadoop System ?BigData
Ans. Distributed file system and Map Reduce system.

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

   Like         Discuss         Correct / Improve     hadoop  bigdata  hadoop system components        frequent


 Q59. Difference between multiple and multi level inheritance ?Core Java
Ans. Multiple Inheritance refers to the concept of a class inheriting multiple classes. Example - Class C extends Class A ,Class B. This is not allowed in Java.

Multilevel Inheritance refers to the concept of Inheritance in a chain. Example - Class B extends Class A, Class C extends Class B. This is permitted in Java.

 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   multiple inheritance  object oriented programming (oops)  oops concepts   multi level inheritance  object oriented programming (oops)  oops concepts      Basic        frequent


 Q60. Can we access private members of the parent class ? i.e Are private members of the class visible in the derived class ?Core Java
Ans. No, If both Parent and Derived are outer classes.

public class Vehicle {
private static String manufacturingDate = "2016";
}

public class Car extends Vehicle{
public static void main(String args[]){
System.out.println(manufacturingDate); // error - The field Vehicle.manufacturingDate is not visible
}
}

Yes, If derived is the inner class of Parent.

public class Vehicle {
private static String manufacturingDate = "2016";
static public class Car extends Vehicle{
public static void main(String args[]){
System.out.println(manufacturingDate); // no problem
}
}
}

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

   Like         Discuss         Correct / Improve     private members   private methods   private variables   inheritance  object oriented programming (oops)  oops concepts   members visibility   inner classes  nexted classes      basic        frequent


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: