Latest java Interview Questions and Answers 2024 for Freshers and Experienced

Java: Frequently Asked Interview Questions and answers. Java is a popular, general-purpose programming language that is widely used for developing desktop, web, and mobile applications. It is known for its "write once, run anywhere" philosophy, which allows Java code to be executed on multiple platforms without modification.


Home->Java Interview Questions and Answers

If you're looking for current Java interview questions and answers, you've come to the right place! This Latest 2024 Question List will provide you with a comprehensive list of trending Java interview questions and answers asked in Top Companies interview round.

Java Interview Questions and Answers Play Quiz On Java  |  More Q&A Click Here

# Question Options Answer
101 In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?
  • Protected
  • Public
  • Static
  • Private
  • Private
    102 All classes in Java are inherited from which class?
  • java.class.object
  • java.lang.class
  • java.lang.Object
  • java.class.inherited
  • java.lang.Object
    103 Using which of the following, multiple inheritance in Java can be implemented?
  • Multithreading
  • Private methods
  • Interfaces
  • Protected methods
  • Interfaces
    104 Which of this keyword must be used to inherit a class?
  • extends
  • extent
  • this
  • super
  • extends
    105 Which of these is supported by method overriding in Java?
  • class
  • Polymorphism
  • Encapsulation
  • Abstraction
  • Polymorphism
    106 If a class inheriting an abstract class does not define all of its function then it will be known as?
  • A simple class
  • interface
  • Abstract
  • Static class
  • Abstract
    107 Which of these is not abstract?
  • Queue
  • List
  • AbstractList
  • Thread
  • Thread
    108 Which of this package is used for handling security related issues in a program?
  • java.lang.security
  • java.awt.image
  • java.security
  • java.io.security
  • java.security
    109 Which of these methods can randomize all elements in a list?
  • randomize()
  • rand()
  • ambiguous()
  • shuffle()
  • shuffle()
    110 Which of these must contain a unique element?
  • List
  • Set
  • Collection
  • Array
  • Set
    111 Which of these interface handle sequences?
  • Collection
  • Comparator
  • List
  • Set
  • List
    112 Which of these is a method of ListIterator used to obtain index of previous element?
  • back()
  • previous()
  • goBack()
  • previousIndex()
  • previousIndex()
    113 Which of these methods can be used to move to next element in a collection?
  • hasNext()
  • shuffle()
  • move()
  • next()
  • next()
    114 Which of these return type of hasNext() method of an iterator?
  • Boolean
  • Double
  • Integer
  • Collections Object
  • Boolean
    115 What is Collection in Java?
  • A group of classes
  • A group of interfaces
  • A group of objects
  • All of above
  • A group of objects
    116 Which of these methods deletes all the elements from invoking collection?
  • refresh()
  • delete()
  • reset()
  • clear()
  • clear()
    117 Which of these classes is not part of Java’s collection framework?
  • Stack
  • Queue
  • Array
  • Maps
  • Maps
    118 Which of these packages contain all the collection classes?
  • java.net
  • java.lang
  • java.util
  • java.awt
  • java.util
    119 Which of these methods is used to retrieve the elements in properties object at specific location?
  • ElementAt()
  • get()
  • getProperty()
  • Elementat()
  • getProperty()
    120 Which of these method is used to insert value and its key?
  • addElement()
  • insertElement()
  • put()
  • set()
  • put()
    121 Which of these class object uses the key to store value?
  • Hashtable
  • Dictionary
  • Map
  • All of above
  • All of above
    122 Which of these methods is used to add elements in vector at specific location?
  • set()
  • add()
  • addElement()
  • AddElement()
  • addElement()
    123 Which of these are legacy classes?
  • Vector
  • Stack
  • Hashtable
  • All of Above
  • All of Above
    124 Which of these methods can be used to obtain set of all keys in a map?
  • keyall()
  • keySet()
  • getAll()
  • getKeys()
  • keySet()
    125 Which of these method is used to remove all keys/values pair from the invoking map?
  • removeAll()
  • clear()
  • remove()
  • delete()
  • remove()
    126 Which of the following is not OOPS concept in Java?
  • Inheritance
  • Encapsulation
  • Polymorphism
  • Compilation
  • Compilation
    127 Which of the following is a type of polymorphism in Java?
  • Compile time polymorphism
  • Execution time polymorphism
  • Multiple polymorphism
  • Multilevel polymorphism
  • Compile time polymorphism
    128 When does method overloading is determined?
  • At run time
  • At compile time
  • At coding time
  • At execution time
  • At compile time
    129 When Overloading does not occur?
  • More than one method with same name but different method signature and different number or type of parameters
  • More than one method with same name, same signature but different number of signature
  • More than one method with same name, same signature, same number of parameters but different type
  • More than one method with same name, same number of parameters and type but different signature
  • More than one method with same name, same number of parameters and type but different signature
    130 Which concept of Java is a way of converting real world objects in terms of class?
  • Polymorphism
  • Encapsulation
  • Abstraction
  • Inheritance
  • Abstraction
    131 Which concept of Java is achieved by combining methods and attribute into a class?
  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation
    132 What is it called if an object has its own lifecycle and there is no owner?
  • Aggregation
  • Composition
  • Encapsulation
  • Association
  • Association
    133 What is it called where child object gets killed if parent object is killed?
  • Aggregation
  • Composition
  • Encapsulation
  • Association
  • Composition
    134 What is it called where object has its own lifecycle and child object cannot belong to another parent object?
  • Aggregation
  • Composition
  • Encapsulation
  • Association
  • Aggregation
    135 Method overriding is combination of inheritance and polymorphism?
  • True
  • False
  • None
  • All of the above
  • True
    136 What is the stored in the object obj in following lines of Java code? -> box obj;
  • Memory address of allocated memory of object
  • NULL
  • Any arbitrary pointer
  • Garbage
  • NULL
    137 Which of these keywords is used to make a class?
  • class
  • struct
  • int
  • none of the mentioned
  • class
    138 Which of the following is a valid declaration of an object of class Box?
  • Box obj = new Box();
  • Box obj = new Box;
  • obj = new Box();
  • new Box obj;
  • Box obj = new Box();
    139 Which of these statement is incorrect?
  • Every class must contain a main() method
  • Applets do not require a main() method at all
  • There can be only one main() method in a program
  • main() method must be made public
  • Every class must contain a main() method
    140 Which of the following statements is correct?
  • Public method is accessible to all other classes in the hierarchy
  • Public method is accessible only to subclasses of its parent class
  • Public method can only be called by object of its class
  • Public method can be accessed by calling object of the public class
  • Public method is accessible to all other classes in the hierarchy
    141 What is the return type of a method that does not return any value?
  • int
  • float
  • void
  • double
  • void
    142 Which of the following is a method having same name as that of it’s class?
  • finalize
  • delete
  • class
  • constructor
  • constructor
    143 Which method can be defined only once in a program?
  • main method
  • finalize method
  • static method
  • private method
  • main method
    144 Which of this statement is incorrect?
  • All object of a class are allotted memory for the all the variables defined in the class
  • If a function is defined public it can be accessed by object of other class by inheritance
  • main() method must be made public
  • All object of a class are allotted memory for the methods defined in the class
  • All object of a class are allotted memory for the methods defined in the class
    145 What is the return type of Constructors?
  • int
  • float
  • void
  • none of the mentioned
  • none of the mentioned
    146 Which keyword is used by the method to refer to the object that invoked it?
  • import
  • catch
  • abstract
  • this
  • this
    147 Which operator is used by Java run time implementations to free the memory of an object when it is no longer needed?
  • delete
  • free
  • new
  • none of the mentioned
  • none of the mentioned
    148 Which function is used to perform some action when the object is to be destroyed?
  • finalize()
  • delete()
  • main()
  • none of the mentioned
  • finalize()
    149 Which of the following statements are incorrect?
  • default constructor is called at the time of object declaration
  • constructor can be parameterized
  • finalize() method is called when a object goes out of scope and is no longer needed
  • finalize() method must be declared protected
  • finalize() method is called when a object goes out of scope and is no longer needed
    150 What is true about private constructor?
  • Private constructor ensures only one instance of a class exist at any point of time
  • Private constructor ensures multiple instances of a class exist at any point of time
  • Private constructor eases the instantiation of a class
  • Private constructor allows creating objects in other classes
  • Private constructor ensures only one instance of a class exist at any point of time
    151 What would be the behaviour if this() and super() used in a method?
  • Runtime error
  • Throws exception
  • compile time error
  • Runs successfully
  • compile time error
    152 What is false about constructor?
  • Constructors cannot be synchronized in Java
  • Java does not provide default copy constructor
  • Constructor can have a return type
  • this and super can be used in a constructor
  • Constructor can have a return type
    153 What is true about Class.getInstance()?
  • Class.getInstance calls the constructor
  • Class.getInstance is same as new operator
  • Class.getInstance needs to have matching constructor
  • Class.getInstance creates object if class does not have any constructor
  • Class.getInstance creates object if class does not have any constructor
    154 What is true about protected constructor?
  • Protected constructor can be called directly
  • Protected constructor can only be called using super()
  • Protected constructor can be used outside package
  • protected constructor can be instantiated even if child is in a different package
  • Protected constructor can only be called using super()
    155 What is not the use of this keyword in Java?
  • Passing itself to another method
  • Calling another constructor in constructor chaining
  • Referring to the instance variable when local variable has the same name
  • Passing itself to method of the same class
  • Passing itself to method of the same class
    156 What would be the behaviour if one parameterized constructor is explicitly defined?
  • Compilation error
  • Compilation succeeds
  • Runtime error
  • Compilation succeeds but at the time of creating object using default constructor, it throws compilation error
  • Compilation succeeds but at the time of creating object using default constructor, it throws compilation error
    157 What would be behaviour if the constructor has a return type?
  • Compilation error
  • Runtime error
  • Compilation and runs successfully
  • Only String return type is allowed
  • Compilation error
    158 What is the process of defining two or more methods within same class that have same name but different parameters declaration?
  • method overloading
  • method overriding
  • method hiding
  • none of the mentioned
  • method overloading
    159 Which of these can be overloaded?
  • Methods
  • Constructors
  • All of the mentioned
  • None of the mentioned
  • All of the mentioned
    160 Which of these is correct about passing an argument by call-by-value process?
  • Copy of argument is made into the formal parameter of the subroutine
  • Reference to original argument is passed to formal parameter of the subroutine
  • Copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument
  • Reference to original argument is passed to formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument
  • Copy of argument is made into the formal parameter of the subroutine
    161 What is the process of defining a method in terms of itself, that is a method that calls itself?
  • Polymorphism
  • Abstraction
  • Encapsulation
  • Recursion
  • Recursion
    162 Which of these access specifiers must be used for main() method?
  • private
  • public
  • protected
  • none of the mentioned
  • public
    163 Which of these is used to access a member of class before object of that class is created?
  • public
  • private
  • static
  • protected
  • static
    164 Which of these is used as a default for a member of a class if no access specifier is used for it?
  • private
  • public
  • public, within its own package
  • protected
  • private
    165 What is the process by which we can control what parts of a program can access the members of a class?
  • Polymorphism
  • Abstraction
  • Encapsulation
  • Recursion
  • Encapsulation
    166 Which of the following statements are incorrect?
  • public members of class can be accessed by any code in the program
  • private members of class can only be accessed by other members of the class
  • private members of class can be inherited by a subclass, and become protected members in subclass
  • protected members of a class can be inherited by a subclass, and become private members of the subclass
  • private members of class can be inherited by a subclass, and become protected members in subclass
    167 Which of these access specifier must be used for class so that it can be inherited by another subclass?
  • public
  • private
  • protected
  • none of the mentioned
  • public
    168 Which one of the following is not an access modifier?
  • Public
  • Private
  • Protected
  • Void
  • Void
    169 All the variables of class should be ideally declared as?
  • private
  • public
  • protected
  • default
  • private
    170 Which of the following modifier means a particular variable cannot be accessed within the package?
  • private
  • public
  • protected
  • default
  • private
    171 How can a protected modifier be accessed?
  • accessible only within the class
  • accessible only within package
  • accessible within package and outside the package but through inheritance only
  • accessible by all
  • accessible within package and outside the package but through inheritance only
    172 What happens if constructor of class A is made private?
  • Any class can instantiate objects of class A
  • Objects of class A can be instantiated only within the class where it is declared
  • Inherited class can instantiate objects of class A
  • classes within the same package as class A can instantiate objects of class A
  • Objects of class A can be instantiated only within the class where it is declared
    173 All the variables of interface should be?
  • default and final
  • default and static
  • public, static and final
  • protect, static and final
  • public, static and final
    174 What is true of final class?
  • Final class cause compilation failure
  • Final class cannot be instantiated
  • Final class cause runtime failure
  • Final class cannot be inherited
  • Final class cannot be inherited
    175 How many copies of static and class variables are created when 10 objects are created of a class?
  • 1, 10
  • 10, 10
  • 10, 1
  • 1, 1
  • 1, 10
    176 Which is the modifier when there is none mentioned explicitly?
  • protected
  • private
  • public
  • default
  • default
    177 String in Java is a?
  • class
  • object
  • variable
  • character array
  • class
    178 Which of these method of String class is used to obtain character at specified index?
  • char()
  • Charat()
  • charat()
  • charAt()
  • charAt()
    179 Which of these keywords is used to refer to member of base class from a subclass?
  • upper
  • super
  • this
  • none of the mentioned
  • super
    180 Which of these method of String class can be used to test to strings for equality?
  • isequal()
  • isequals()
  • equal()
  • equals()
  • equals()
    181 Which of the following statements are incorrect?
  • String is a class
  • Strings in java are mutable
  • Every string is an object of class String
  • Java defines a peer class of String, called StringBuffer, which allows string to be altered
  • Strings in java are mutable
    182 Which of this keyword can be used in a subclass to call the constructor of superclass?
  • super
  • this
  • extent
  • extends
  • super
    183 What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?
  • Method overloading
  • Method overriding
  • Method hiding
  • None of the mentioned
  • Method overriding
    184 Which of these keywords can be used to prevent Method overriding?
  • static
  • constant
  • protected
  • final
  • final
    185 Which of these is supported by method overriding in Java?
  • Abstraction
  • Encapsulation
  • Polymorphism
  • None of the mentioned
  • Polymorphism
    186 What is not type of inheritance?
  • Single inheritance
  • Double inheritance
  • Hierarchical inheritance
  • Multiple inheritance
  • Double inheritance
    187 Using which of the following, multiple inheritance in Java can be implemented?
  • Interfaces
  • Multithreading
  • Protected methods
  • Private methods
  • Interfaces
    188 All classes in Java are inherited from which class?
  • java.lang.class
  • java.class.inherited
  • java.class.object
  • java.lang.Object
  • java.lang.Object
    189 In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?
  • Protected
  • Private
  • Public
  • Static
  • Private
    190 If super class and subclass have same variable name, which keyword should be used to use super class?
  • super
  • this
  • upper
  • classname
  • super
    191 Static members are not inherited to subclass.
  • True
  • False
  • Not Sure
  • None
  • True
    192 Which of the following is used for implementing inheritance through an interface?
  • inherited
  • using
  • extends
  • implements
  • implements
    193 Which of the following is used for implementing inheritance through class?
  • inherited
  • using
  • extends
  • implements
  • extends
    194 What would be the result if a class extends two interfaces and both have a method with same name and signature? Lets assume that the class is not implementing that method.
  • Runtime error
  • Compile time error
  • Code runs successfully
  • First called method is executed successfully
  • Compile time error
    195 Which of these class is superclass of every class in Java?
  • String class
  • Object class
  • Abstract class
  • ArrayList class
  • Object class
    196 Which of these method of Object class can clone an object?
  • Objectcopy()
  • copy()
  • Object clone()
  • clone()
  • Object clone()
    197 Which of these method of Object class is used to obtain class of an object at run time?
  • get()
  • void getclass()
  • Class getclass()
  • None of the mentioned
  • Class getclass()
    198 Which of these keywords can be used to prevent inheritance of a class?
  • super
  • constant
  • class
  • final
  • final
    199 Which of these keywords cannot be used for a class which has been declared final?
  • abstract
  • extends
  • abstract and extends
  • none of the mentioned
  • abstract
    200 Which of these class relies upon its subclasses for complete implementation of its methods?
  • Object class
  • abstract class
  • ArrayList class
  • None of the mentioned
  • abstract class

    Are you preparing for a Java developer interview? Brush up on your skills with our comprehensive collection of Java interview questions. Covering everything from basic syntax to advanced concepts, our questions will help you demonstrate your knowledge and experience with the Java programming language.This page is designed to test a candidate's understanding of the key concepts in the Java programming language and their ability to apply that knowledge to real-world situations. Get ready to impress your interviewer and land your dream job with our Java interview question page

    This page provides a comprehensive collection of Java questions and answers, covering a wide range of topics related to the language, such as:

    • Basic syntax and data types
    • Object-oriented programming concepts
    • Control structures, such as loops and conditions
    • Exception handling
    • Collections and generics
    • Multithreading and concurrency
    • Advanced topics such as functional programming and design patterns

    Additionally, you will also find useful tips on how to prepare for your Java interview, such as reviewing your coding skills, studying up on the latest technologies and trends, and practicing your interviewing skills.

    Whether you are a junior developer or an experienced professional, this guide will help you ace your Java interview and land your dream job. So, whether you are looking for your first job as a developer or looking to make a change in your career, this guide will be a valuable resource for you.