Home apps Development Gaming Mobile TECHNOLOGY Software Hordware OTHERS Kids Baby Mom Toys Cloths Multiple Choice Question (MCQ) Login

Basic Java and Java OOPS Interview Questions

Categories: OTHERS

Q.1. What is the difference between an array and an array list?

Ans.

Array

(i) Cannot contain values of different data types

(ii) Size must be defined at the time of declaration

(iii) Need to specify the index in order to add data

(iv) Arrays are not type parameterized

(v) Arrays can contain primitive data types as well as objects

 

ArrayList

(i) Can contain values of different data types.

(ii) Size can be dynamically changed

(iii) No need to specify the index

(iv) Arraylists are type

(v) Arraylists can contain only objects, no primitive data types are allowed

 

Q.2. What is a Map in Java?

 

Ans. In Java, Map is an interface of Util package which maps unique keys to values. The Map interface is not a subset of the main Collection interface and thus it behaves little different from the other collection types. Below are a few of the characteristics of Map interface:

 

  1. Map doesn’t contain duplicate keys.
  2. Each key can map at max one value.

 

Q.3. What is collection class in Java? List down its methods and interfaces.

 

Ans. In Java, the collection is a framework that acts as an architecture for storing and manipulating a group of objects. Using Collections you can perform various tasks like searching, sorting, insertion, manipulation, deletion, etc. Java collection framework includes the following:

(i) Interfaces

(ii) Classes

(iii) Methods

 

Java OOPS Interview Questions

 

Q.4. What is Polymorphism?

 

Ans. Polymorphism is briefly described as “one interface, many implementations”. Polymorphism is a characteristic of being able to assign a different meaning or usage to something in different contexts – specifically, to allow an entity such as a variable, a function, or an object to have more than one form. There are two types of polymorphism:

 

  1. Compile time polymorphism
  2. Run time polymorphism

Compile time polymorphism is method overloading whereas Runtime time polymorphism is done using inheritance and interface.

 

Q.5. What is abstraction in Java?

 

Ans. Abstraction refers to the quality of dealing with ideas rather than events. It basically deals with hiding the details and showing the essential things to the user. Thus you can say that abstraction in Java is the process of hiding the implementation details from the user and revealing only the functionality to them. Abstraction can be achieved in two ways:

 

(i) Abstract Classes (0-100% of abstraction can be achieved)

(ii) Interfaces (100% of abstraction can be achieved)

 

Q.6. What is the difference between abstract classes and interfaces?

Ans.

 

Abstract Class

(i) An abstract class can provide complete, default code and/or just the details that have to be overridden

(ii) In the case of an abstract class, a class may extend only one abstract class

(iii) An abstract class can have non-abstract methods

(iv) An abstract class can have instance variables

(v) An abstract class can have any visibility: public, private, protected

(vi) If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly

(vii) An abstract class can contain constructors

(viii) Abstract classes are fast

 

Interfaces

(i) An interface cannot provide any code at all, just the signature

(ii) A Class may implement several interfaces

(iii) All methods of an Interface are abstract

(iv) An Interface cannot have instance variables

(v) An Interface visibility must be public (or) none

(vi) If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method

(vii) An Interface cannot contain constructors

(viii) Interfaces are slow as it requires extra indirection to find the corresponding method in the actual class

 

Q.7. What is inheritance in Java?

 

Ans. Inheritance in Java is the concept where the properties of one class can be inherited by the other. It helps to reuse the code and establish a relationship between different classes. Inheritance is performed between two types of classes:

 

  1. Parent class (Super or Base class)
  2. Child class (Subclass or Derived class)

 

A class which inherits the properties is known as Child Class whereas a class whose properties are inherited is known as Parent class.

 

Q.8. What are the different types of inheritance in Java?

 

Ans. Java supports four types of inheritance which are:

 

  • Single Inheritance: In single inheritance, one class inherits the properties of another i.e there will be only one parent as well as one child class.
  • Multilevel Inheritance: When a class is derived from a class which is also derived from another class, i.e. a class having more than one parent class but at different levels, such type of inheritance is called Multilevel Inheritance.
  • Hierarchical Inheritance: When a class has more than one child classes (subclasses) or in other words, more than one child classes have the same parent class, then such kind of inheritance is known as hierarchical.
  • Hybrid Inheritance: Hybrid inheritance is a combination of two or more types of inheritance.

 

Q.9. What is method overloading and method overriding?

 

Ans. Method Overloading:

(i) In Method Overloading, Methods of the same class shares the same name but each method must have a different number of parameters or parameters having different types and order.

(ii) Method Overloading is to “add” or “extend” more to the method’s behavior.

(iii) It is a compile-time polymorphism.

(iv) The methods must have a different signature.

(v) It may or may not need inheritance in Method Overloading.

 

Q.10. What is encapsulation in Java?

 

Ans. Encapsulation is a mechanism where you bind your data(variables) and code(methods) together as a single unit. Here, the data is hidden from the outer world and can be accessed only via current class methods. This helps in protecting the data from any unnecessary modification. We can achieve encapsulation in Java by:

 

  1. Declaring the variables of a class as private.
  2. Providing public setter and getter methods to modify and view the values of the variables.

Top articles
6 Tips for Parents to Help Your Child Develop Effective Study Skills Published at:- 7 Money-Saving Content-Marketing Tricks Every Marketer Should Try Published at:- 10 Effective List Structure Techniques Published at:- 5 Reasons Why Digital Marketing Is Essential for Any Business Published at:- Is Video the Most Effective Form of Communication? Published at:- Eight Diabetes Legends Busted Published at:- What Are the Requirements for Chemical Storage in India Published at:- Dengue Symptoms and Treatment Published at:- General Knowledge Mostly Asked Questions for New Students Published at:- Navigating the Midjourney of Artificial Intelligence: Progress, Challenges, and Future Prospects Published at:- Celebrate Navratri with a High-Protein Twist: Badam ka Halwa Recipe Published at:- Nourishing the Spirit: Navratri Fasting and Feasting Published at:- Diwali Special: Soan Papdi Sweet Recipe Published at:- Mastering the Art of Healthy Sleep: Strategies for Restful Nights and Energized Days Published at:- Which Country First Celebrated First World AIDS Day Published at:- The Significance of Republic Day Published at:- Guest list for the Ayodhya Ram Mandir opening Published at:- Hairstyle Trends to Complement On Your Outfit Published at:- From Spice Markets to International Acclaim: Indian Chutneys' Journey to the Top Dips List Published at:- Basic Java and Java OOPS Interview Questions Published at:- NEET (Zoology MCQs) Published at:- July, 2024 Current Affairs (MCQs) Published at:- Important Days and Events (MCQs) Published at:- Reports and Indices (MCQs) Published at:-

Basic Java and Java OOPS Interview Questions