OOPS interview questions for experienced/OOPS Interview Questions and Answers for Freshers & Experienced

What is a wrapper class in java?

The wrapper class in java provides the mechanism to convert primitive type into object and object into primitive type.
The automatic conversion of primitive type into an object is known as autoboxing and object to primitive type is unboxing.

What is a static blank final variable in java?

A final static variable that is not initialized at the time of declaration is known as a static blank final variable.
It can be initialized only in static block.

What is a ternary operator in java?

The ternary operator is a conditional operator that takes three operands, and it evaluates the condition as true or false.

For example:

public class JavaHungry {
public static void main(String args[])
int x = 10;
int y = 25;
System.out.println((x > y) ? "x is greater than y" : " x is less than y");

x is less than y

Difference between constructors and methods in java?

a. A constructor is used to initializing an object whereas method is used to exhibit functionality of an object.

b. Constructors are invoked implicitly but methods are invoked explicitly.

Can Interfaces have a constructor in java?

No, the interface cannot have constructors (Constructor is being called during the creation of object).

From a method can we call a constructor directly in java?

No, Constructors can't be called directly, they can be called implicitly when the new keyword creates an object. Methods can be called explicitly on an object that has already been created with the help of a new keyword.

In a class which is the default access modifier in java?

The default access modifier is "default" which is also known as "package-private" (though you can't use this explicitly). It means the field will be visible to the same package to which the class belongs. Java uses a "default" access modifier when no access modifier is present.

What are the problems might be created when you are trying to implement multiple inheritance concept in java?

The operations like casting, constructor chaining might cause problems when trying to implement
multiple inheritance. Even the compiler gets complications as to call which class method and which class gets priority.

Define virtual functions.

The functions that help achieve runtime polymorphism are a part of functions present in the parent class and overridden by a subclass.

What does the keyword virtual represented in the method definition?

It represents that we can override the method.

So, above are the mentioned interview questions & answers for programming jobs, candidates should go through to clear the job interview easily.

What is the purpose of a virtual destructor?

Virtual destructor helps to destruct the resources correctly when you delete a base class pointer pointing to the derived class object.

How would you describe the difference between an "is-a" and a "has-a" relationship?

When you have an 'is-a' relationship, it has to do with inheritance and the classes which inherit. The sub class acts like a parent class. For instance, an onion is a vegetable. So you would code in a way that states the class is the onion that extends the vegetable. When you're dealing with 'has-a' relationships, it is more about composition which produces instances of references to other objects. For example, a swimming pool has a hot tub. In OOP, you'd create a class pool and within it an instance of a hot tub.

How do you differentiate between a class and an object?

When I'm programming code using OOP, the class determines what the object itself is made of. A class is like a blueprint or template that shows the inner workings of an object. Each object has its own qualities and behaviors based on its class.

Can you use this () and super () both in a constructor?

1. Both super() and this() functions are used to make constructor calls. this() is used to call the current class constructor, while super() is used to call the base class’s constructor.
2. But we can’t use both this() and super() together in a constructor, as it will give a compile-time error.
3. Because super() and this() must be the first executable statement, if anyone is written first, the other will become the second statement and vice-versa. That's why we can't use this() and super() together.

Why is the constructor not overridden?

You cannot override the constructor because it looks like a method, but it is not. It doesn’t have the return type, and the name is the same as the class name. If you treat it as a method and write a super class's constructor in the sub-class compiler expecting a return type, it will generate a compile-time error.

Can the constructor be private?

Yes, you can declare a constructor as private. Once a constructor is declared private, you cannot create an object of a class. We use private constructors in the Singleton Design Patterns.

Rules for private constructors:

1. The private constructor does not allow object creation outside the class and a class to be subclassed.
2. We can use a private constructor when all the methods are static.
3. If we extend a class containing a private constructor, then a compile-time error will occur.

Explain how polymorphism is supported by C++.

Because polymorphism means having many forms, it is an important feature of OOP. There are different classes of functions with the same name and parameters, though with differing implementations. C++ supports ad-hoc polymorphism, parametric polymorphism and subtype polymorphism.

How do procedural programming and OOP differ?

Procedural programming operates on functions, whereas object-oriented programming has a focus on real-world objects. When working within a procedural language, you are working with an entire program that operates on a sequence of functions, rather than that of an OOP language that encapsulates data and prioritizes the states and behaviors of objects.

What are the different types of constructors?

* Parameterized constructors
* Default constructors
* Copy constructors
* Conversion constructors
* Move constructors

What are the different types of Polymorphism?

OOPs supports two different types of Polymorphism as below:

1. Static Binding (or Compile time) Polymorphism
2. Dynamic Binding (or Runtime) Polymorphism

Static Binding or Compile time polymorphism

This polymorphism type uses method overloading or function overloading. Certain conditions are conducive for static polymorphism as below:

* Parameter types should be different.
* The sequence of parameters can be different.
* A number of parameters for one method should be different from another method.
* The matching type and number of arguments of static polymorphism invoke the overloaded functions.
* Dynamic Binding or Runtime polymorphism
* This polymorphism type uses method overriding. Through pointers and virtual functions, we can achieve overriding.
* When a derived class has a definition for one of the base class’s member functions, that base class is method overridden.

Is an error basically the same as an exception?

An error means a problem that the program should not catch while the exception implies a condition that should be caught by the program.

Define exception handling

Exception handling refers to the mechanism used for handling the exceptions raised during program execution. It allows for the graceful handling of undesirable results.

Can we overload the main() method in Java also give an example?

Yes, we can also overload the main() method in Java. Any number of main() methods can be defined in the class, but the method signature must be different. Consider the following code.

class OverloadMain
public static void main(int a) //overloaded main method
public static void main(String args[])
System.out.println("main method invoked");

Is it possible to overload a constructor?

Yes, the constructors can be overloaded by changing the number of arguments accepted by the constructor or by changing the data type of the parameters. For example:

public class Demo
Demo(String str) //overloaded constructor
Demo(double d) //overloaded constructor

What are the levels of data abstraction?

There are three levels of data abstraction:

<> Physical Level: It is the lowest level of data abstraction. It shows how the data is actually stored in memory.

<> Logical Level: It includes the information that is actually stored in the database in the form of tables. It also stores the relationship among the data entities in relatively simple structures. At this level, the information available to the user at the view level is unknown.

<> View Level: It is the highest level of data abstraction. The actual database is visible to the user. It exists to ease the availability of the database by an individual user.

What is data abstraction and how can we achieve data abstraction?

It is one of the most important features of OOP. It allows us to show only essential data or information to the user and hides the implementation details from the user. A real-world example of abstraction is driving a car. When we drive a car, we do not need to know how the engine works (implementation) we only know how ECG works.

There are two ways to achieve data abstraction

* Abstract class
* Abstract method

What is the difference between a base class and a superclass?

The base class is the root class- the most generalized class. At the same time, the superclass is the immediate parent class from which the other class inherits.

What are the main features of OOPS?

Some of the main features in OOPS include Classes, Objects, Data Abstraction, Encapsulation, Inheritance, and Polymorphism. OOP is a programming paradigm that is based on the idea of objects.

Who is the father of OOPS?

The father of the Object-Oriented Programming System is considered to be Alan Kay by some people. He identified some characteristics as basics to OOP Kay 1993:1. He coined OOPs around 1966 or 1967 when he was at grad school.

What is the concept of OOPS?

OOPS or Object-Oriented Programming System is a programming concept that mainly works based on Encapsulation, Abstraction, Polymorphism, and Inheritance. The usual concept of OOPs is to create objects, use them again all through the program, and finally manipulate these objects to fetch our results.

What are the 3 principles of OOP?

The three main principles of Object-Oriented Programming are Encapsulation, inheritance, and polymorphism.

What is a pure virtual function?

A pure virtual function is only declared in the parent class. It is also referred to as an abstract function. Pure virtual functions do not contain any definition in the base class. They must be redefined in the subclass for the implementation needed.

What is a virtual function?

A virtual function is defined in the parent class and may have definitions implemented. A subclass can override these definitions.

Can you call the base class method without creating an instance?

•Yes, you are allowed to call the base class without instantiating it but there are some conditions that are applicable:

•If it is a static method

•The base class is inherited by some other subclass

What is exception handling?

Exception handling in Object-Oriented Programming is the most important concept. It is used to manage errors. An exception handler help to throw errors and then catch the error in order to solve them.

What is an exception?

An exception is a kind of message that interrupts and comes up when there is an issue with normal execution of a program. Exceptions provide a error and transfer that error to the exception handler to resolve it. The state of the program is saved as soon as an exception is raised.

Explain about Tokens.

Tokens in the Java program are the smallest elements that the compiler recognizes. Identifiers, keywords, literals, operators, and separators are examples of tokens.

When the finalize method is used?

finalize method is called just before the object is about to be garbage collected. This method overrides to minimize memory leaks, undertake cleanup activities by removing system resources.

Is Operator overloading supported in Java?

Operator overloading is not supported by Java as,

<> It makes the interpreter put more effort to understand the actual functionality of the operator making code complex and difficult to compile.

<> Operator overloading makes programs more error-prone.

<> However, the feature of operator overloading can be achieved in method overloading in a simple, clear, and error-free way.

Can you explain base class, subclass, and superclass?

Base class, sub class, and super class in Java are explained as follows:

* Base class or parent class is a super class and is a class from which sub class or child class is derived.

* Sub class is a class that inherits attributes (properties) and methods (behavior) from the base class.

What types of arguments can be used in Java?

For Java methods and functions, parameter data can be sent and received in different ways. If methodB() is called from methodA(), methodA() is a caller function and methodB() is called function, arguments sent by methodA() is actual arguments and parameters of methodB() is called formal arguments.

Call By Value: Changes made to formal parameter (parameters of methodB()) do not get sent back to the caller (methodA()), This method is called call by value. Java supports the call by value.
Call by Reference: Changes made to formal parameter (parameters of methodB()) are sent back to the caller (parameters of methodB()).
Any changes in formal parameters (parameters of methodB()) are reflected in actual parameters (arguments sent by methodA()). This is called call by reference.

What are the languages come under oops concept?

Simula is known as the first object-oriented programming language, the most popular OOP languages are:

Visual Basic . NET.

How do you create an instance of an abstract class?

You cannot create an instance of an abstract class since it lacks implementation logic in its methods. You first need to create a subclass that implements all the methods before an object can be initialized.

Can you please elaborate on ‘access specifiers’?

Access specifiers are special keywords that control the accessibility of methods or classes etc. They are also called access modifiers and are used to achieve the encapsulation. e.g., the keywords public, private, and protected are some examples of access specifiers.

How can data abstraction be accomplished?

Data abstraction can be accomplished through either an abstract class or an abstract method.

What is the difference between new and override?

The new modifier instructs the compiler to use the new implementation instead of the base class function. Whereas, Override modifier helps to override the base class function.

virtual: indicates that a method may be overridden by an inheritor

override: Overrides the functionality of a virtual method in a base class, providing different functionality.

new: Hides the original method (which doesn't have to be virtual), providing different functionality. This should only be used where it is absolutely necessary.

When you hide a method, you can still access the original method by upcasting to the base class. This is useful in some scenarios, but dangerous.

Name the operators that cannot be overload.

1. Scope Resolution Operator (::)
2. Ternary Operator (? :)
3. Member Access or Dot Operator (.)
4. Pointer to Member Operator (.*)
5. sizeof operator

Distinguish between multiple and multi-level inheritances?

In the case of the multiple inheritance, a class inherits more than one parent class. In contrast, multi-level inheritance means that class inherits from another class, which is a subclass of some other parent class.

What is Coupling in OOP and why it is helpful?

In programming, separation of concerns is known as coupling. It means that an object cannot directly change or modify the state or behavior of other objects. It defines how closely two objects are connected together. There are two types of coupling, loose coupling, and tight coupling.

Objects that are independent of one another and do not directly modify the state of other objects is called loosely coupled. Loose coupling makes the code more flexible, changeable, and easier to work with.

Objects that depend on other objects and can modify the states of other objects are called tightly coupled. It creates conditions where modifying the code of one object also requires changing the code of other objects. The reuse of code is difficult in tight coupling because we cannot separate the code.

What is constructor chaining?

In OOPs, constructor chaining is a sequence of invoking constructors (of the same class) upon initializing an object. It is used when we want to invoke a number of constructors, one after another by using only an instance. In other words, if a class has more than one constructor (overloaded) and one of them tries to invoke another constructor, this process is known as constructor chaining. In C++, it is known as constructor delegation and it is present from C++ 11.

R4R Team
R4R provides OOPS Freshers questions and answers (OOPS Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,OOPS interview questions for experienced,OOPS Freshers & Experienced Interview Questions and Answers,OOPS Objetive choice questions and answers,OOPS Multiple choice questions and answers,OOPS objective, OOPS questions , OOPS answers,OOPS MCQs questions and answers Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for OOPS fresher interview questions ,OOPS Experienced interview questions,OOPS fresher interview questions and answers ,OOPS Experienced interview questions and answers,tricky OOPS queries for interview pdf,complex OOPS for practice with answers,OOPS for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .