SlideShare a Scribd company logo
Core Java
Java Interview Questions & Answers - 1
What does this presentation Include?
These set of slides include basic Java Interview Questions and answers which can be
very helpful for a Software Engineer to attend an interview. I also have included a set of
bit complex Java Questions in ‘Java Interview Questions & Answers - 2’ presentation.
Introduction
1. What is a class and an object in OOP?
• An object is a real world entity which has a state and a behavior.
• In OOP object refers to a particular instance of a class.
• A Class is a Collection of Objects. It is a blue print which can be used to
create objects
2. What are the basic Fundamentals of OOP?
• Abstraction,
• Polymorphism
• Inheritance
• Encapsulation
3. Explain Abstraction
Through the process of abstraction, a programmer hides all but the relevant data
about an object in order to reduce complexity and increase efficiency.
OR
Hiding all the internal details and showing functionality is called abstraction.
4. Explain Polymorphism and state two ways
to implement polymorphism
Polymorphism is the ability of an object to take on many forms.
OR
One task performed in different ways.
Ways to implement it…
– Method Overloading
– Method Overriding
– When parent class reference is used to refer to a child class object
5. Explain Encapsulation and state how
encapsulation can be applied in a java
class
Binding and wrapping code and data together as a single unit is called as
encapsulation
How to apply in a java class?
Having all the fields/properties of the class private and implementing public
getters and setters to access them
6. Explain Inheritance and State two
advantages of using Inheritance
One object acquires properties and behaviors of a parent object
• Provides code reusability
• Used to achieve runtime polymorphism
• Code enhancement- built on what you have, without altering the present funct
ionality.
7. What are the main data types available in
java? State all the primitive data types
Primitive data types and reference/object data types
There are eight primitive data types in java
• short
• byte
• int
• long
• double
• float
• char
• boolean
8. What is static keyword mean in java?
Static says that it always operates within the class (belongs to the class) not in
specific objects.
9.What do you mean by operator precedence
in java?
Java has well-defined rules for specifying the order in which the operators in an
expression are evaluated when the expression has several operators.
For example, multiplication and division have a higher precedence than addition
and subtraction.
10. Can we override and overload main
method of a java application
We can overload main method by changing the no of arguments or the type of
the arguments but we cannot override main method.
11. State three features of a constructor in
java
• Constructor name must be as same as the class name
• Must not have an explicit return type
• Constructor need not to be invoked explicitly
• Java compiler provides a default constructor if you haven’t implemented any
constructors explicitly
12. What is constructor overloading?
A class having more than one constructor having changed each of its parameters
changed (no of parameters or type of parameters)
13. How can you call one constructor from an
other constructor
Using this() keyword
e.g:-
Employee(int a){
}
Employee(int a String b){
this(a);
}
14. State two ways to copy objects in java
Copy by constructor and using clone() method
15. What are the access modifiers in java?
• private
• Default
• protected
• public
16. What happens when fields of a class are
marked as protected?
Those fields can only be accessed from its subclasses
17. What is method overloading and how can
it be implemented?
If a class have multiple methods by same name but different parameters it is
known as method overloading
Can implement his by changing the types of the parameters or the number of the
parameters
18. Can method overloading be implemented
by changing the return type of a method? If n
ot why?
No. It gives a compile time error because there will be an ambiguity when calling
the methods
19. State three places where the ‘super’ key
word is used in java
• Super is used to refer the immediate parent class instance variable
e.g:- super.length
• Super() is used to invoke the immediate parent class constructor
• Super is used to invoke immediate parent class method e.g:- super.calculate()
20. What is runtime polymorphism?
Since in method overriding both the super class and the subclass methods have
the same method, compiler doesn’t figure out which method to be invoked during
compile time. In this case JVM decides which method to call during runtime. This
is called as runtime polymorphism
21. What is method overriding in java?
If subclass provides the specific implementation of a method that has been provi
ded in the parent class, it is known as method overriding.
22. Define rules of method overriding?
• Method must have the same name of the super class method
• Method must have the same parameter as in the parent class
• There must be an IS-A relationship
23. Can we override methods by changing
the return type?
Yes. We can override methods by changing their return type only if their return
type is a sub type.
24. Can we override static methods in java?
No. Static methods cannot be overridden thus the main method if a java program
also cannot be overridden
25. State two differences between HashMap
and HashTable
• HashMap permits one null key and any number of null values in it whereas
HashTable doesn’t allow null values
• HashTable is Synchronized (two thread cannot access the HashTable at the
same time) whereas HashMap is not synchronized
• HashMap is not thread safe but HashTable is thread safe
• HashMap are much faster than HashTable
26. What is an Exception and what is
Exception handling
Exception is an unexpected behavior of a program which could possibly quit the
program during runtime unexpectedly.
By handling the exceptions we allow the applications to run its normal flow.
27. State two Checked Exceptions
• IOException
• SQLEXception
28. State two unchecked exceptions
(runtime exceptions)
• ArithmeticException
• NumberformatException
• NullPointerException
• ArrayindexOutOfBoundsException

More Related Content

PPTX
Basics of Java
PPTX
Java interview questions 2
PPT
Most Asked Java Interview Question and Answer
PPTX
Object+oriented+programming+in+java
PPT
Object Oriented Programming with Java
DOCX
Basic java important interview questions and answers to secure a job
DOCX
Core java notes with examples
PPTX
oops concept in java | object oriented programming in java
Basics of Java
Java interview questions 2
Most Asked Java Interview Question and Answer
Object+oriented+programming+in+java
Object Oriented Programming with Java
Basic java important interview questions and answers to secure a job
Core java notes with examples
oops concept in java | object oriented programming in java

What's hot (20)

DOCX
Java questions for viva
PDF
Java Reflection
PDF
Java inheritance
PPT
DOC
Java interview questions
PPT
Core Java interview questions-ppt
PDF
Java Interview Questions by NageswaraRao
PPT
Core java
PPT
Java Tutorial
ODP
OOP java
PPTX
OCP Java (OCPJP) 8 Exam Quick Reference Card
PDF
Java Threads
PDF
20 most important java programming interview questions
PDF
Basic Java Programming
DOCX
Interview Questions and Answers for Java
PPTX
C# interview
PPTX
Object oriented programming in java
PPTX
Polymorphism in java
PPT
Java basic tutorial by sanjeevini india
PPT
Java Basics
Java questions for viva
Java Reflection
Java inheritance
Java interview questions
Core Java interview questions-ppt
Java Interview Questions by NageswaraRao
Core java
Java Tutorial
OOP java
OCP Java (OCPJP) 8 Exam Quick Reference Card
Java Threads
20 most important java programming interview questions
Basic Java Programming
Interview Questions and Answers for Java
C# interview
Object oriented programming in java
Polymorphism in java
Java basic tutorial by sanjeevini india
Java Basics
Ad

Viewers also liked (20)

DOC
Qtp Faq
DOC
Web Dictionary
PPT
Collection Framework in java
PDF
Java Programming - 01 intro to java
PPTX
Core java online training
ODP
Toolbarexample
PPT
02basics
DOCX
Java Exception handling
PDF
Java quick reference v2
PDF
Yaazli International Spring Training
PDF
Yaazli International Hibernate Training
PPT
09events
PDF
Yaazli International AngularJS 5 Training
PPTX
Exception handling in java
PDF
Yaazli International Web Project Workshop
PPTX
For Loops and Variables in Java
DOC
Non ieee dot net projects list
PDF
Java Basic Operators
ODP
Singleton pattern
Qtp Faq
Web Dictionary
Collection Framework in java
Java Programming - 01 intro to java
Core java online training
Toolbarexample
02basics
Java Exception handling
Java quick reference v2
Yaazli International Spring Training
Yaazli International Hibernate Training
09events
Yaazli International AngularJS 5 Training
Exception handling in java
Yaazli International Web Project Workshop
For Loops and Variables in Java
Non ieee dot net projects list
Java Basic Operators
Singleton pattern
Ad

Similar to Java interview questions 1 (20)

PDF
Java_Question-Bank.docx-1.pdf
PDF
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
PDF
Android interview questions
PDF
Android interview questions
PDF
__ Java Technical round questions .pdf soo
DOCX
Corejavainterviewquestions.doc
PDF
Top 100 Java Interview Questions with Detailed Answers
PDF
Java interview questions and answers
DOC
Core java interview questions
PPTX
Java J2EE Interview Questions Part-1
PPTX
Java J2EE Interview Questions Part-1
PDF
Core Java Interview Questions with Answers.pdf
PDF
java-2marks-qzcvhsvnmdjdvjndcsdcuestions-with-answer.pdf
DOC
Java interview faq's
DOCX
Java Core Parctical
PDF
Java interview questions
DOC
Core java questions
DOC
Core java questions
DOC
Faqs in java
Java_Question-Bank.docx-1.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
Android interview questions
Android interview questions
__ Java Technical round questions .pdf soo
Corejavainterviewquestions.doc
Top 100 Java Interview Questions with Detailed Answers
Java interview questions and answers
Core java interview questions
Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1
Core Java Interview Questions with Answers.pdf
java-2marks-qzcvhsvnmdjdvjndcsdcuestions-with-answer.pdf
Java interview faq's
Java Core Parctical
Java interview questions
Core java questions
Core java questions
Faqs in java

Recently uploaded (20)

PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Introduction to Artificial Intelligence
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPT
Introduction Database Management System for Course Database
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Digital Strategies for Manufacturing Companies
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
medical staffing services at VALiNTRY
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
AI in Product Development-omnex systems
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Nekopoi APK 2025 free lastest update
Softaken Excel to vCard Converter Software.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
How Creative Agencies Leverage Project Management Software.pdf
Introduction to Artificial Intelligence
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Introduction Database Management System for Course Database
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Digital Strategies for Manufacturing Companies
Navsoft: AI-Powered Business Solutions & Custom Software Development
medical staffing services at VALiNTRY
How to Choose the Right IT Partner for Your Business in Malaysia
2025 Textile ERP Trends: SAP, Odoo & Oracle
AI in Product Development-omnex systems
Wondershare Filmora 15 Crack With Activation Key [2025
Understanding Forklifts - TECH EHS Solution
Nekopoi APK 2025 free lastest update

Java interview questions 1

  • 1. Core Java Java Interview Questions & Answers - 1
  • 2. What does this presentation Include? These set of slides include basic Java Interview Questions and answers which can be very helpful for a Software Engineer to attend an interview. I also have included a set of bit complex Java Questions in ‘Java Interview Questions & Answers - 2’ presentation. Introduction
  • 3. 1. What is a class and an object in OOP? • An object is a real world entity which has a state and a behavior. • In OOP object refers to a particular instance of a class. • A Class is a Collection of Objects. It is a blue print which can be used to create objects
  • 4. 2. What are the basic Fundamentals of OOP? • Abstraction, • Polymorphism • Inheritance • Encapsulation
  • 5. 3. Explain Abstraction Through the process of abstraction, a programmer hides all but the relevant data about an object in order to reduce complexity and increase efficiency. OR Hiding all the internal details and showing functionality is called abstraction.
  • 6. 4. Explain Polymorphism and state two ways to implement polymorphism Polymorphism is the ability of an object to take on many forms. OR One task performed in different ways. Ways to implement it… – Method Overloading – Method Overriding – When parent class reference is used to refer to a child class object
  • 7. 5. Explain Encapsulation and state how encapsulation can be applied in a java class Binding and wrapping code and data together as a single unit is called as encapsulation How to apply in a java class? Having all the fields/properties of the class private and implementing public getters and setters to access them
  • 8. 6. Explain Inheritance and State two advantages of using Inheritance One object acquires properties and behaviors of a parent object • Provides code reusability • Used to achieve runtime polymorphism • Code enhancement- built on what you have, without altering the present funct ionality.
  • 9. 7. What are the main data types available in java? State all the primitive data types Primitive data types and reference/object data types There are eight primitive data types in java • short • byte • int • long • double • float • char • boolean
  • 10. 8. What is static keyword mean in java? Static says that it always operates within the class (belongs to the class) not in specific objects.
  • 11. 9.What do you mean by operator precedence in java? Java has well-defined rules for specifying the order in which the operators in an expression are evaluated when the expression has several operators. For example, multiplication and division have a higher precedence than addition and subtraction.
  • 12. 10. Can we override and overload main method of a java application We can overload main method by changing the no of arguments or the type of the arguments but we cannot override main method.
  • 13. 11. State three features of a constructor in java • Constructor name must be as same as the class name • Must not have an explicit return type • Constructor need not to be invoked explicitly • Java compiler provides a default constructor if you haven’t implemented any constructors explicitly
  • 14. 12. What is constructor overloading? A class having more than one constructor having changed each of its parameters changed (no of parameters or type of parameters)
  • 15. 13. How can you call one constructor from an other constructor Using this() keyword e.g:- Employee(int a){ } Employee(int a String b){ this(a); }
  • 16. 14. State two ways to copy objects in java Copy by constructor and using clone() method
  • 17. 15. What are the access modifiers in java? • private • Default • protected • public
  • 18. 16. What happens when fields of a class are marked as protected? Those fields can only be accessed from its subclasses
  • 19. 17. What is method overloading and how can it be implemented? If a class have multiple methods by same name but different parameters it is known as method overloading Can implement his by changing the types of the parameters or the number of the parameters
  • 20. 18. Can method overloading be implemented by changing the return type of a method? If n ot why? No. It gives a compile time error because there will be an ambiguity when calling the methods
  • 21. 19. State three places where the ‘super’ key word is used in java • Super is used to refer the immediate parent class instance variable e.g:- super.length • Super() is used to invoke the immediate parent class constructor • Super is used to invoke immediate parent class method e.g:- super.calculate()
  • 22. 20. What is runtime polymorphism? Since in method overriding both the super class and the subclass methods have the same method, compiler doesn’t figure out which method to be invoked during compile time. In this case JVM decides which method to call during runtime. This is called as runtime polymorphism
  • 23. 21. What is method overriding in java? If subclass provides the specific implementation of a method that has been provi ded in the parent class, it is known as method overriding.
  • 24. 22. Define rules of method overriding? • Method must have the same name of the super class method • Method must have the same parameter as in the parent class • There must be an IS-A relationship
  • 25. 23. Can we override methods by changing the return type? Yes. We can override methods by changing their return type only if their return type is a sub type.
  • 26. 24. Can we override static methods in java? No. Static methods cannot be overridden thus the main method if a java program also cannot be overridden
  • 27. 25. State two differences between HashMap and HashTable • HashMap permits one null key and any number of null values in it whereas HashTable doesn’t allow null values • HashTable is Synchronized (two thread cannot access the HashTable at the same time) whereas HashMap is not synchronized • HashMap is not thread safe but HashTable is thread safe • HashMap are much faster than HashTable
  • 28. 26. What is an Exception and what is Exception handling Exception is an unexpected behavior of a program which could possibly quit the program during runtime unexpectedly. By handling the exceptions we allow the applications to run its normal flow.
  • 29. 27. State two Checked Exceptions • IOException • SQLEXception
  • 30. 28. State two unchecked exceptions (runtime exceptions) • ArithmeticException • NumberformatException • NullPointerException • ArrayindexOutOfBoundsException