Interview Questions and Answers for 'Program' | 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
 Q31. Find the repeating number using O(n) time and constant space.Algorithm
Ans. http://www.geeksforgeeks.org/find-duplicates-in-on-time-and-constant-extra-space/

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

   Like         Discuss         Correct / Improve     algorithm   program   code   coding  makemytrip.com


 Q32. How is static and dynamic polymorphism achieved in Java ?Core Java
Ans. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding.

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

   Like         Discuss         Correct / Improve     static polymorphism  object oriented programming (oops)  oops concepts   dynamic polymorphism  object oriented programming (oops)  oops concepts   polymorphism  object oriented programming (oops)  oops concepts   overloading   overriding   broadridg     Asked in 1 Companies      basic        frequent


  Q33. How is multiple inheritance implemented in Java ?Core Java
Ans. There was no multiple inheritance in java before version 8 as implementing multiple interfaces cannot be termed as inheritance.

With Java 8 , came the concept of default methods wherein the class implementing the interface carries the default implementation from the interface and hence facilitating multiple inheritance.

 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   inheritance  object oriented programming (oops)  oops concepts   oops concept     Asked in 10 Companies        frequent


 Q34. What is multilevel inheritance ?Core Java
Ans. Multi Level Inheritance is multi level hierarchy of classes. Here is the example - http://www.buggybread.com/2015/09/java-se-class-diagram-classes-that_603.html

Class RoleList extends ArrayList which in turn extends AbstractList which in turn extends AbstractCollection.

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

   Like         Discuss         Correct / Improve     multilevel inheritance  object oriented programming (oops)  oops concepts  inheritance  object oriented programming (oops)  oops concepts  oops concepts     Asked in 3 Companies      basic

Try 1 Question(s) Test


 Q35. Can I run a java program without creating any class ?
Ans. No, It requires creation of atleast one Class. Creating an object of that class is not compulsory as we can write all our logic within main method which is static.

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

   Like         Discuss         Correct / Improve     java program without creating any class


 Q36. Does default methods introduce multiple inheritance and the Diamond problem in Java 8 ?Core Java
Ans. Default methods results in multiple inheritance of behavior and not of state. In case we try to implement multiple interfaces with default method having same name and signature, and don't override it in implementation class, it will throw an error.

For example -

interface MyInterface {
public void default myMethod(){
}
}

interface MyInterface2 {
public void default myMethod(){
}
}

class MyClass implements MyInterface,MyInterface2 {
}

This code will compilation error "Duplicate Default Method"

if we specify the definition of myMethod() in myClass, compiler won't complain and there is no conflict and MyClass can use overridden definition. But if we don't override myMethod() in MyClass, Java would be in conflict as to what definition should be carried to MyClass and hence throws compilation error.

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

   Like         Discuss         Correct / Improve     default methods  java 8  multiple inheritance  object oriented programming (oops)  oops concepts  diamond problem   interfaces


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


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


 Q39. Write a Java Program to check Armstrong Number ?Core Java
Ans. http://www.programmingsimplified.com/java/source-code/java-program-armstrong-number

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

   Like         Discuss         Correct / Improve     program  code  coding  armstrong number     Asked in 1 Companies


 Q40. Write a Program to print the positive and negative numbers separetlyCore Java
Ans. int[] arr = {1,-1,2,-3,3,-4,4,5,6,-5,-6,-7,-8,8,9,-9};
List positiveNumbers = new ArrayList<>();
List negativeNumbers = new ArrayList<>();
for(int i = 0; i < arr.length(); i ){
if(I < 0){
negativeNumbers.add(i);
} else {
positiveNumbers.add(i);
}
}

System.out.println("Positive Numbers:" + positiveNumbers);
System.out.println("Negative Numbers:" + negativeNumbers);

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

   Like         Discuss         Correct / Improve     code  program  coding     Asked in 1 Companies


 Q41. Is exit a keyword in Java ?Core Java
Ans. No exit is a method to exit execution of a program.

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

   Like         Discuss         Correct / Improve     exit  keywords  exit a program     Asked in 1 Companies


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


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


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


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


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


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


 Q48. How would you explain the statement "Java Programs are collection of objects" ?Core Java
Ans. Java Programs are collection of objects that communicates with each other to get a task accomplished. To add to those objects, there are common spaces ( static i.e common for objects belonging to a class ) that are used too.

We can visualize objects as departments of an organization in real world. Just like Task gets initiated in one department and then files are moved across different departments to get work done. In a similar fashion, a task is initiated in one object ( having main method ) and then information ( through POJOs / DTOs ) is moved across objects to accomplish a task.

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

   Like         Discuss         Correct / Improve     objects  Java Programs are collection of objects  real life example of object communication


 Q49. Write a method, that compare two numbers and return the bigger one ?Core Java
Ans. int compare(int a, int b) {
a>b? return a: return b;
}

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

   Like         Discuss         Correct / Improve     code  program  coding     Asked in 1 Companies      basic


 Q50. Write a Program for insertion sort.Core Java
 This question was recently asked at 'Ola Cabs'.This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     program  code  coding  insertion sort   sort     Asked in 1 Companies


Very frequently asked. Usually among very first few questions.
 Q51. 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


 Q52. What are the different types of advices in AOP ?Spring
 This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     spring app  spring  aspect oriented programming


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


 Q54. Is Runtime Polymorphism possible without Inheritance ?Core Java
Ans. Yes, Runtime Polymprohism requires either Class inheritance or Interface implementation.

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

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


 Q55. What is composition ?Core Java
 This question was recently asked at 'MST Solutions'.This question is still unanswered. Can you please provide an answer.


  Sample Code for composition

 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  oops concepts     Asked in 1 Companies      basic        frequent


 Q56. What are the drawbacks of Reactive extensions ?ReactiveX
Ans. Reactive extensions have a steep learning curve which makes it confusing for beginner and intermediate developers.

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

   Like         Discuss         Correct / Improve     RxJava  ReactiveX  Reactive Programming


 Q57. What is virtual table with respect to method overriding in Java ?Core Java
 This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     vtable  virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts


 Q58. How is the virtual method table implemented in Java?Core Java
 This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts      expert        rare


 Q59. How many VTables are there for each class ? Core Java
Ans. There is one VTable for each class.

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

   Like         Discuss         Correct / Improve     virtual table method  vtable  runtime polymorphism  object oriented programming (oops)  oops concepts   method overriding      intermediate        rare


 Q60. Can a class extend itself in Java ?Core Java
Ans. No

 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


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: