×

Top 15 Java OOPS Interview Questions for 2024

1) What are the advantages of Java Package?

Advantages of Java package are:
  • Provides access protection
  • Removes naming collision
  • Easily maintained

2) What are the types of Access Modifiers in Java?

Two types of Access Modifiers in Java are: 1) access modifiers
  • private
  • default
  • protected
  • public
2) non-access modifiers
  • static
  • abstract
  • synchronized
  • native
  • volatile
  • transient etc

3) What are the types of constructors in Java?

Two types of constructors in java are :
  • Default constructor
  • Parameterized constructor

4) What is the difference between constructor and method in Java?

Differnce between constructor and method :
Constructor Method
It is used to initialize the state of an object It is used to expose behaviour of an object
Invoked implicitly Invoked explicitly
Must not have return type Must have return type
It's name must be same as the class name. It's name may or may not be same as class name.

5) What are the different oops concept in Java?

The different oops concepts are :
  • Polymorphism
  • Inheritance
  • Encapsulation
  • Abstraction
  • Composition
  • Association
  • Aggregation

6) What are the restrictions of static method in Java?

Two main restrictions of static method are:
  • It can't use non static data member
  • super and this can't be used in static context

7) What will be the output of following piece of code?

class TutorialExam  
{    
int b=98;   
public static void main(String args[])  
{    
System.out.println(b);    
}    
}
OUTPUT:
Compile Time Error

8) Can we override java main method?

We can't override main method in java because main method is static.

9) Write a program in java for Single inheritance ?

Example of Single inheritance:
class Mom{    
void eat()  
{  
System.out.println("eating...");  
}    
}    
class Baby extends Mom  
{    
void run()  
{  
System.out.println("Running...");  
}    
}    
class TutorialExam{    
public static void main(String args[]){    
Baby b=new Baby();    
b.run();    
b.eat();    
}  
}

10) What are the types of inheritance in Java?

There are five types of inheritance in java:
  • Single inheritance
  • Multilevel inheritance
  • Hierarchical inheritance
  • Multiple inheritance
  • Hybrid inheritance

11) Write a program in java of super keyword where super() is provided by the compiler implicitly?

Example:
class Cars  
{    
Cars()  
{  
System.out.println("Choose a car : BMW, AUDI, JAGUAR");  
}    
}    
class BMW extends Cars  
{    
BMW()  
{    
System.out.println("Selected car :BMW");    
}    
}    
class TestCars  
{    
public static void main(String args[])  
{    
BMW d=new BMW();    
}  
}

12) Write a program in java of Runtime polymorphism?

Example of Runtime Polymorphism:
class Car  
{    
void run()  
{  
System.out.println("Running");  
}    
}    
class Audi extends Car  
{    
void run()  
{  
System.out.println("Running with 150km/h");  
}    
public static void main(String args[])  
{    
Car c = new Audi();    
c.run();    
}    
}

13) What are the types of binding in Java?

Two types of binding in java are:
  • Static binding(early binding)
  • Dynamic binding(late binding)

14) What are the ways to achieve Abstraction in Java?

Two ways to achieve abstraction in java:
  • By using Abstract class
  • By using Interface

15) What are the commonly used methods of Object class in Java?

Commonly used methods of Object class in java are:
  • public int hashCode()
  • public String toString()
  • public final void notify()
  • public final void notifyAll()
  • public final Class getClass()
  • public boolean equals(Object obj)
  • protected void finalize()throws Throwable
  • public final void wait()throws InterruptedException
  • protected Object clone() throws CloneNotSupportedException
  • public final void wait(long timeout)throws InterruptedException
  • public final void wait(long timeout, int nanos)throws InterruptedException

Related Topics

Top 16 Yii PHP Framework Interview Questions for 2024

1) What is Yii Framework? Yii is an open source, web application framework based on MVC. It is written in PHP and used to design PHP applications. This application was started...

4 minutes read.

Top 16 OpenStack Interview Questions for 2024

Most Frequently Asked OpenStack Interview Questions and Answers for Freshers 1. Describe OpenStack. OpenStack is designed as the future of cloud computing and developed as free and open-source software that facilitates a...

8 minutes read.

Polymer.js Interview Questions

1) What is Polymer.js? Polymer.js is an open source JavaScript library. It is developed by Google. It is used to develop web applications for using of web components like HTML. 2) Describe...

3 minutes read.

Top 16 Arduino Interview Questions for 2024

1) What is Arduino? Arduino is an open source electronic platform. It is based on easy-to-use hardware and software. It able to read input signal. It is used to write and...

2 minutes read.

VB.NET Interview Questions

1) What is VB.NET? VB.NET stands for Visual Basic .NET. It is an object oriented programming language. It is implemented on .NET framework and launched by Microsoft in 2001. 2) Who is...

3 minutes read.

Top 18 UiPath Interview Questions for 2024

RPA UiPath Interview Questions and Answers for Fresher  1. What is RPA? RPA is an acronym for Robotic Process Automation. Robotic In RPA, Robotic is termed as an entity or machine which tries to...

7 minutes read.

Top 15 CSS Buttons Interview Questions for 2024

1) What is CSS buttons? CSS buttons is used to create awesome button. It provides huge collection of CSS library files. 2) What are the CSS libraries to create buttons? There are following...

5 minutes read.

Top 30 Cassandra Interview Questions for 2024

1) Explain. What is Cassandra? Cassandra is an open source data storage system. It was developed at Facebook for inbox search and designed for storing and managing large amount of data. 2)...

5 minutes read.

Top 15 Foundation Interview Questions for 2024

1) What is Foundation? Foundation is a front-end framework that is for designing beautiful responsive websites. This framework is compatible with all types of devices and provides you with HTML, CSS...

2 minutes read.

Top 15 RequireJs Interview Questions for 2024

1) What is RequireJs? RequireJs is a open source JavaScript library which is used to maintain dependencies between JavaScript files and modular programming. 2) What are the features of RequireJs? Following are the...

3 minutes read.

Top 20 HTTP Interview Questions for 2024

1) What is HTTP? HTTP stands for Hypertext Transfer Protocol. It is a set of rules for transferring of data on WWW (World Wide Web). 2) What are the basic Features of...

4 minutes read.

Top 16 Groovy interview Questions for 2024

1) What is Groovy? Groovy is an object oriented programming language. It is based on java platform. It can also be used as scripting language. 2) Who designed the Groovy? James Strachan designed...

2 minutes read.

Top 15 Pure CSS Interview Questions for 2024

1) What is Pure CSS? Pure is a CSS (Cascading Style Sheet) framework. It is a collection of small set of responsive CSS modules. We can integrate it to any web...

5 minutes read.

Top 27 JavaScript Interview Questions for 2024

1) Define Undeclared and Undefined Variables? Undeclared variable are defined as these variable is neither defined nor exist in the program. If program calls this variable then it causes Runtime error. Undefined variable...

5 minutes read.

Top 25 CoffeeScript Interview Questions for 2024

1) What is CoffeeScript? It is a language that compiles into JavaScript. CoffeeScript is an attempt to expose good parts of JavaScript so, that user can code more easily. 2) Name the...

3 minutes read.

SSIS Interview Questions and Answers

Q.1 What is SSIS? SQL Server Integration Service (SSIS) is a component of Microsoft SQL Server. It is a powerful ETL tool that is used for building enterprise-level data transformation and...

5 minutes read.

Top 15 SVG Interview Questions for 2024

1) What is SVG? SVG stands for Scalable Vector Graphics, It is XML based format used to draw dimentional vector images. It is a W3C standard. SVG supports all image formats. 2) What are...

2 minutes read.

Top 16 Ionic Interview Questions for 2024

Top 20 Ionic Interview Questions and Answers for Freshers 1) What is Ionic framework? Ionic is open source HTML5 framework used for hybrid mobile application development. It provides tools and services for...

3 minutes read.

Top 15 Meteor Interview Questions for 2024

1) What is Meteor or MeteorJS? Meteor is a JavaScript platform used for developing web and mobile applications. Applications develop using Meteor framework supports different platforms (like windows, android, ios). Meteor...

4 minutes read.

C++ | C Plus Plus Interview Questions for 2024

1) Write a program in C++ to print "Hello World"? #include <iostream.h>     #include <conio.h>   void main()    {       clrscr();       cout << "Hello World";     getch();     } 2) Write a program in C++ to enter two integers and find their sum and average ? #include <iostream.h>   #include <conio.h>   void main()   {   clrscr();   int x,y;   float sum,average;   cout << "Enter 2 integers : " << endl;   cin>>x>>y;   sum=x+y;   average=sum/2;   cout <<"The sum is:"<< sum << endl;   cout <<"The average is:"<< average << endl;   getch();   } 3) Write a program in...

5 minutes read.