Wipro Limited – Technical Interview Question Bank – Part 1

Q. What is inheritance in Java?

Ans. Inheritance is when a class inherits the properties of another class. The class which inherits is called the child class and the class from which the properties are inherited is called the parent class.

Q. What is importance inheritance in Java?
Ans. Inheritance improves the reusability of code.

Q. Explain the above with an example.
Ans. Suppose we have a class car. Now, in general each car has tires, doors, wipers etc. So we define a parent class with these characteristics and then the child classes can inherit these common properties and further have specific qualities of its own in its own class. Thus we don’t have to define the common properties repeatedly for each car.

Q. Keyword used to inherit a class in Java?
Ans. Extends.

Q. Difference between multiple and multilevel inheritance?
Ans. Multiple inheritance is when a child class has multiple parent classes. Multilevel inheritance means a hierarchy of inheritances in a system.

Q. Java supports both multiple and multilevel inheritance?
Ans. Java supports multilevel inheritance in general but it can support multilevel inheritance by using interfaces.

Q. What are interfaces in Java?
Ans. These are reference types in Java. They contain all abstract methods. They can be implemented by classes.

Q. Why interfaces?
Ans. All functions in an interface need to be defined in the class implementing it. Thus in a team if a person makes one part of the code and he needs some functions to be implemented necessary for proper working of that code, he can use an interface which when implemented will force the next team member(who updates or works on the next version of the project) to define the mandatory functions (for correct functionality).

Q. Keyword for inheritance in interfaces?
Ans. Implements.

Q. What is abstraction in Java?
Ans. Abstraction is hiding irrelevant data and showing only what is mandatory.

Q. What is an abstract class?
Ans. An abstract class is a class which may or may not have all abstract methods. These cannot be instantiated but can be inherited.

Q. What is polymorphism?
Ans. Different behavior of an object in different environment.

Q. How does Java implement polymorphism?
Ans. Overriding and Overloading.

Q. Difference between overriding and overloading?
Ans. Overriding means having two methods with the same method name and parameters (i.e., method signature). Overloading occurs when two or more methods in one class have the same method name but different parameters.

Q. Write a code to exhibit overriding.
Ans. Code

                                                                                                 Continued to Part 2

Leave a Reply

Your email address will not be published. Required fields are marked *