0% found this document useful (0 votes)
15 views21 pages

Java Cse-Cic-Csd-20apc0512-20apc3609-20apc3207 II II Vivavoce Ay 2023 24 TSR

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views21 pages

Java Cse-Cic-Csd-20apc0512-20apc3609-20apc3207 II II Vivavoce Ay 2023 24 TSR

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI

AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

Q1. Explain JDK?


It stands for Java Development Kit

It is the tool necessary to compile, document and package Java programs.

It contains JRE + development tools.

Q2. Why Java is platform independent?

Java is called platform independent because of its byte codes which can run on any system
irrespective of its underlying operating system.

Q3. Why Java is not 100% Object-oriented?

Java is not 100% Object-oriented because it makes use of eight primitive data types such as
boolean, byte, char, int, float, double, long, short which are not objects.

Q4. What are wrapper classes in Java?

Wrapper classes convert the Java primitives into the reference types (objects). Every primitive
data type has a class dedicated to it. These are known as wrapper classes because they “wrap” the
primitive data type into an object of that class. Refer to the below image which displays different
primitive type, wrapper class and constructor argument.

Q5. What are constructors in Java?

In Java, constructor refers to a block of code which is used to initialize an object. It must have
the same name as that of the class. Also, it has no return type and it is automatically called when
an object is created.

There are two types of constructors:

1. Default Constructor: In Java, a default constructor is the one which does not take any inputs. In
other words, default constructors are the no argument constructors which will be created by
default in case you no other constructor is defined by the user. Its main purpose is to initialize the
instance variables with the default values. Also, it is majorly used for object creation.
2. Parameterized Constructor: The parameterized constructor in Java, is the constructor which is
capable of initializing the instance variables with the provided values. In other words, the
constructors which take the arguments are called parameterized constructors

Collected & Prepared By: T. SREENIVASULA REDDY Page 1 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

Q6. What is the difference between equals() and == in Java?

Equals() method is defined in Object class in Java and used for checking equality of two objects
defined by business logic.

“==” or equality operator in Java is a binary operator provided by Java programming language
and used to compare primitives and objects. public boolean equals(Object o) is the method
provided by the Object class. The default implementation uses == operator to compare two
objects. For example: method can be overridden like String class. equals() method is used to
compare the values of two objects.

Q7. When can you use the super keyword?

In Java, the super keyword is a reference variable that refers to an immediate parent class object.

When you create a subclass instance, you’re also creating an instance of the parent class, which is
referenced to by the super reference variable.

Q8. Why pointers are not used in Java?

Java doesn’t use pointers because they are unsafe and increases the complexity of the program.
Since, Java is known for its simplicity of code, adding the concept of pointers will be
contradicting. Moreover, since JVM is responsible for implicit memory allocation, thus in order
to avoid direct access to memory by the user, pointers are discouraged in Java

In Java, access modifiers are special keywords which are used to restrict the access of a class,
constructor, data member and method in another class. Java supports four types of access
modifiers:

1. Default
2. Private
3. Protected
4. Public

Q9. Define a Java Class.

A class in Java is a blueprint which includes all your data. A class contains fields (variables) and
methods to describe the behavior of an object. Let’s have a look at the syntax of a class.

1classAbc {

Collected & Prepared By: T. SREENIVASULA REDDY Page 2 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

2member variables // class body

3methods}

Q10. What is an object in Java and how is it created?

An object is a real-world entity that has a state and behavior. An object has three characteristics:

1. State
2. Behavior
3. Identity

An object is created using the ‘new’ keyword. For example:

ClassNameobj = new ClassName();

Q11. What are the main concepts of OOPs in Java?

Object-Oriented Programming or OOPs is a programming style that is associated with concepts


like:

1. Inheritance: Inheritance is a process where one class acquires the properties of another.
2. Encapsulation: Encapsulation in Java is a mechanism of wrapping up the data and code
together as a single unit.
3. Abstraction: Abstraction is the methodology of hiding the implementation details from
the user and only providing the functionality to the users.
4. Polymorphism: Polymorphism is the ability of a variable, function or object to take
multiple forms.

Q12. Differentiate between the constructors and methods in Java?

Methods Constructors

1. Used to represent the behavior of an object 1. Used to initialize the state of an object

2. Must have a return type 2. Do not have any return type

Collected & Prepared By: T. SREENIVASULA REDDY Page 3 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

3. Needs to be invoked explicitly 3. Is invoked implicitly

4. No default method is provided by the 4. A default constructor is provided by the compiler if the
compiler class has none

5. Method name may or may not be same as 5. Constructor name must always be the same as the class
class name name

Q13. What is final keyword in Java?

final is a special keyword in Java that is used as a non-access modifier. A final variable can be
used in different contexts such as:

● final variable

When the final keyword is used with a variable then its value can’t be changed once assigned. In
case the no value has been assigned to the final variable then using only the class constructor a
value can be assigned to it.

● final method
When a method is declared final then it can’t be overridden by the inheriting class.

● final class
When a class is declared as final in Java, it can’t be extended by any subclass class but it can
extend other class.

Q14. What is Java String Pool?

Java String pool refers to a collection of Strings which are stored in heap memory. In this,
whenever a new object is created, String pool first checks whether the object is already present in
the pool or not. If it is present, then the same reference is returned to the variable else new object
will be created in the String pool and the respective reference will be returned.

Q15. Differentiate between static and non-static methods in Java.

Static Method Non-Static Method


1. The static keyword must be used before the 1. No need to use the static keyword before
method name the method name

Collected & Prepared By: T. SREENIVASULA REDDY Page 4 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

2. It is called using the class


2. It is can be called like any general method
(className.methodName)
3. It can access any static method and any
3. They can’t access any non-static instance
static variable without creating an instance
variables or methods
of the class

Q16. Why Java Strings are immutable in nature?

In Java, string objects are immutable in nature which simply means once the String object is
created its state cannot be modified. Whenever you try to update the value of that object instead
of updating the values of that particular object, Java creates a new string object. Java String
objects are immutable as String objects are generally cached in the String pool. Since String
literals are usually shared between multiple clients, action from one client might affect the rest. It
enhances security, caching, synchronization, and performance of the application.

Q17. What is the difference between an array and an array list?

Array ArrayList
Cannot contain values of different data types Can contain values of different data types.
Size must be defined at the time of
Size can be dynamically changed
declaration
Need to specify the index in order to add
No need to specify the index
data

Arrays are not type parameterized Arraylists are type

Arrays can contain primitive data types as Arraylists can contain only objects, no primitive
well as objects data types are allowed

Q18. What is Polymorphism?

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

Collected & Prepared By: T. SREENIVASULA REDDY Page 5 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

Q19. What is abstraction in Java?

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:

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


2. Interfaces (100% of abstraction can be achieved)

Q20. What do you mean by an interface in Java?

An interface in Java is a blueprint of a class or you can say it is a collection of abstract methods
and static constants. In an interface, each method is public and abstract but it does not contain
any constructor. Thus, interface basically is a group of related methods with empty bodies

Q21. What is inheritance in Java?

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

Q22. What are the different types of inheritance in Java?

Java supports four types of inheritance which are:

1. 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.
2. 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.
3. 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.

Collected & Prepared By: T. SREENIVASULA REDDY Page 6 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

4. Hybrid Inheritance: Hybrid inheritance is a combination of two or more types of


inheritance.

Q23. What is method overloading and method overriding?

Method Overloading :

● 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.
● Method Overloading is to “add” or “extend” more to the method’s behavior.
● It is a compile-time polymorphism.
● The methods must have a different signature.
● It may or may not need inheritance in Method Overloading.

Method Overriding:

● In Method Overriding, the subclass has the same method with the same name and exactly the
same number and type of parameters and same return type as a superclass.
● Method Overriding is to “Change” existing behavior of the method.
● It is a run time polymorphism.
● The methods must have the same signature.
● It always requires inheritance in Method Overriding

Q24. What is multiple inheritance? Is it supported by Java?

If a child class inherits the property from multiple classes is known as multiple inheritance. Java
does not allow to extend multiple classes.

The problem with multiple inheritance is that if multiple parent classes have the same method
name, then at runtime it becomes difficult for the compiler to decide which method to execute
from the child class.

Therefore, Java doesn’t support multiple inheritance. The problem is commonly referred to as
Diamond Problem

Q24. What is encapsulation in Java?

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:

Collected & Prepared By: T. SREENIVASULA REDDY Page 7 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

● Declaring the variables of a class as private.


● Providing public setter and getter methods to modify and view the values of the variables.

Q25. What is a constructor overloading in Java?

In Java, constructor overloading is a technique of adding any number of constructors to a class


each having a different parameter list. The compiler uses the number of parameters and their
types in the list to differentiate the overloaded constructors.

Q 26) Name the Java IDE’s?


Answer: Eclipse and NetBeans are the IDE’s of JAVA.

Q 27) What is meant by the Local variable and the Instance variable?
Answer:
Local variables are defined in the method and scope of the variables that exist inside the method
itself.
Instance variable is defined inside the class and outside the method and the scope of the variables
exists throughout the class

Q 28) What is meant by Abstract class?


Answer: We can create the Abstract class by using the “Abstract” keyword before the class name.
An abstract class can have both “Abstract” methods and “Non-abstract” methods that are a concrete
class.
Abstract method:
The method which has only the declaration and not the implementation is called the abstract method
and it has the keyword called “abstract”. Declarations ends with a semicolon.

Q 29) What is the meaning of Collections in Java?


Answer: Collection is a framework that is designed to store the objects and manipulate the design to
store the objects.
Collections are used to perform the following operations:
● Searching
● Sorting
● Manipulation
● Insertion
● Deletion
A group of objects is known as collections. All the classes and interfaces for collecting are available
in Java util package.

Q 30) What are all the Classes and Interfaces that are available in the collections?
Answer: Given below are the Classes and Interfaces that are available in Collections:
Interfaces:

Collected & Prepared By: T. SREENIVASULA REDDY Page 8 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

● Collection
● List
● Set
● Map
● Sorted Set
● Sorted Map
● Queue
Classes:
● Lists:
● Array List
● Vector
● Linked List
Sets:
● Hash set
● Linked Hash Set
● Tree Set
Maps:
● Hash Map
● Hash Table
● TreeMap
● Linked Hashed Map
Queue:
● Priority Queue

Q 31) What is meant by Exception?


Answer: An Exception is a problem that can occur during the normal flow of execution. A method
can throw an exception when something wails at runtime. If that exception couldn’t be handled, then
the execution gets terminated before it completes the task.
If we handled the exception, then the normal flow gets continued. Exceptions are a subclass of
java.lang.Exception.

Q 32) What are the types of Exceptions?


Answer: There are two types of Exceptions. They are explained below in detail.
a) Checked Exception:
These exceptions are checked by the compiler at the time of compilation. Classes that extend
Throwable class except Runtime exception and Error are called checked Exception.

Checked Exceptions must either declare the exception using throws keyword (or) surrounded by
appropriate try/catch.

For Example, ClassNotFound Exception


b) Unchecked Exception:

Collected & Prepared By: T. SREENIVASULA REDDY Page 9 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

These exceptions are not checked during the compile time by the compiler. The compiler doesn’t
force to handle these exceptions. It includes:
● Arithmetic Exception
● ArrayIndexOutOfBounds Exception

Q33) What are the different ways to handle exceptions?


Answer: Two different ways to handle exceptions are explained below:
a) Using try/catch:
The risky code is surrounded by try block. If an exception occurs, then it is caught by the catch block
which is followed by the try block.

b) By declaring throws keyword:

At the end of the method, we can declare the exception using throws keyword.

Q 34) What are the Exception handling keywords in Java?


Answer: Enlisted below are the two Exception Handling Keywords:
a) try:
When a risky code is surrounded by a try block. An exception occurring in the try block is caught by
a catch block. Try can be followed either by catch (or) finally (or) both. But any one of the blocks is
mandatory.

b) catch:
This is followed by a try block. Exceptions are caught here.

c) finally:
This is followed either by try block (or) catch block. This block gets executed regardless of an
exception. So generally clean up codes are provided here

Q 35) What is the final keyword in Java?


Answer:
Final variable: Once a variable is declared as final, then the value of the variable could not be
changed. It is like a constant.

Q36) What is a Thread?


Answer: In Java, the flow of execution is called Thread. Every java program has at least one thread
called the main thread, the main thread is created by JVM. The user can define their own threads by
extending the Thread class (or) by implementing the Runnable interface. Threads are executed
concurrently.

Q 37) How do you make a thread in Java?

Collected & Prepared By: T. SREENIVASULA REDDY Page 10 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

Answer: There are two ways available to make a thread.


a) Extend Thread class: Extending a Thread class and override the run method. The thread is
available in java.lang.thread

Q 38) Explain about join () method.


Answer: Join () method is used to join one thread with the end of the currently running thread.

Q 39) Explain about wait () method.


Answer: wait () method is used to make the thread to wait in the waiting pool. When the wait ()
method is executed during a thread execution then immediately the thread gives up the lock on the
object and goes to the waiting pool. Wait () method tells the thread to wait for a given amount of
time.
Then the thread will wake up after notify () (or) notify all () method is called.

Wait() and the other above-mentioned methods do not give the lock on the object immediately until
the currently executing thread completes the synchronized code. It is mostly used in synchronization.

Q 40) Difference between notify() method and notifyAll() method in Java.


Answer: The differences between notify() method and notifyAll() method are enlisted below:
notify() notifyAll()

This method is used to send a signal to wake up a single This method sends the signal to wake up all the t
thread in the waiting pool. in a waiting spool.

Q 41) When to use the Runnable interface Vs Thread class in Java?


Answer: If we need our class to extend some other classes other than the thread then we can go with
the runnable interface because in java we can extend only one class.
If we are not going to extend any class then we can extend the thread class.

Q 42) Difference between start() and run() method of thread class.


Answer: Start() method creates a new thread and the code inside the run () method is executed in the
new thread. If we directly called the run() method then a new thread is not created and the currently
executing thread will continue to execute the run() method.

Q 43) What is Multi-threading?


Answer: Multiple threads are executed simultaneously. Each thread starts its own stack based on the
flow (or) priority of the threads

Q 44) Explain the thread life cycle in Java.


Answer: Thread has the following states:
● New
● Runnable

Collected & Prepared By: T. SREENIVASULA REDDY Page 11 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

● Running
● Non-runnable (Blocked)
● Terminated

Q 45) What is the disadvantage of Synchronization?


Ans: Synchronization is not recommended to implement all the methods. Because if one thread
accesses the synchronized code then the next thread should have to wait. So it makes a slow
performance on the other end.

Q46. What happens if an exception is not handled in a program?

Ans: If an exception is not handled in a program using try catch blocks, program gets
aborted and no statement executes after the statement which caused exception
throwing.

Q47. What’s meant by anonymous class?

Ans: An anonymous class is a class defined without any name in a single line of code
using new keyword.

Q48. What is a Local class in Java?

Ans: In Java, if we define a new class inside a particular block, it’s called a local
class. Such a class has local scope and isn’t usable outside the block where its defined.

49. Why is the main method static in Java?

The main method is always static because static members are those methods that belong to the
classes, not to an individual object. So if the main method will not be static then for every object,
It is available. And that is not acceptable by JVM. JVM calls the main method based on the class
name itself. Not by creating the object.
Because there must be only 1 main method in the java program as the execution starts from the
main method. So for this reason the main method is static.

50. What is the main objective of garbage collection?

The main objective of this process is to free up the memory space occupied by the unnecessary
and unreachable objects during the Java program execution by deleting those unreachable
objects.

Collected & Prepared By: T. SREENIVASULA REDDY Page 12 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

● This ensures that the memory resource is used efficiently, but it provides no guarantee
that there would be sufficient memory for the program execution

51. What part of memory - Stack or Heap - is cleaned in garbage collection


process?

Heap

52. What is the difference between the ‘throw’ and ‘throws’ keyword in java?

● The ‘throw’ keyword is used to manually throw the exception to the calling method.
● And the ‘throws’ keyword is used in the function definition to inform the calling method
that this method throws the exception. So if you are calling, then you have to handle the
exception.

53. Is it mandatory for a catch block to be followed after a try block?

No, it is not necessary for a catch block to be present after a try block. - A try block should be
followed either by a catch block or by a finally block. If the exceptions likelihood is more, then
they should be declared using the throws clause of the method

54 What is the difference between sleep and wait in Java?


Answer: Both are used to pause thread that is currently running, however, sleep() is
meant for short pause because it does not release lock, while wait() is meant for
conditional wait.

This is why it releases lock, which can then be developed by a different thread to alter
the condition of which it is waiting.

55 What is the difference between final, finalize and finally?


Answer: Final is a modifier which you can apply to variable, methods, and classes. If
you create a variable final, this means its value cannot be changed once initialised.

Finalise is a method, which is called just before an object is a garbage collected,


allowing it a final chance to save itself, but the call to finalise is not definite.

Collected & Prepared By: T. SREENIVASULA REDDY Page 13 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

Finally is a keyword which is used in exception handling, along with try and catch. The
finally block is always implemented regardless of whether an exception is thrown from
try block or not

56 What is the difference between ArrayList and LinkedList in Java?


Answer: The main difference between them is that ArrayList is supported by array data
structure, supports random access. LinkedList is backed by linked list data structure and
doesn’t support random access
\

Q57. What is a finally block? Is there a case when finally will not execute?

Finally block is a block which always executes a set of statements. It is always associated with a
try block regardless of any exception that occurs or not.
Yes, finally will not be executed if the program exits either by calling System.exit() or by
causing a fatal error that causes the process to abort.

Q58. What is synchronization?

Synchronization refers to multi-threading. A synchronized block of code can be executed by only


one thread at a time. As Java supports execution of multiple threads, two or more threads may
access the same fields or objects. Synchronization is a process which keeps all concurrent
threads in execution to be in sync. Synchronization avoids memory consistency errors caused
due to inconsistent view of shared memory. When a method is declared as synchronized the
thread holds the monitor for that method’s object. If another thread is executing the synchronized
method the thread is blocked until that thread releases the monitor

Q59. Can we write multiple catch blocks under single try block?

Yes we can have multiple catch blocks under single try block but the approach should be from
specific to general.

Q60. What is a Thread?

A thread is the smallest piece of programmed instructions which can be executed independently
by a scheduler. In Java, all the programs will have at least one thread which is known as
the main thread. This main thread is created by the JVM when the program starts its execution.
The main thread is used to invoke the main() of the program.

Collected & Prepared By: T. SREENIVASULA REDDY Page 14 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

61. Define Dynamic Method Dispatch.


The Dynamic method dispatch is a process where the method call is executed during the runtime.
A reference variable is used to call the super-class. This process is also known as Run-Time
Polymorphism.

Q62) What is Type casting in Java?

When we assign a value of one data type to the different data type then these two data
types may not be compatible and needs a conversion. If the data types are compatible (for
example assigning int value to long) then java does automatic conversion and does not
require casting. However if the data types are not compatible then they need to be casted
for conversion.

Q63) What is an Array?

An array is a collection (group) of fixed number of items. Array is a homogeneous data


structure which means we can store multiple values of same type in an array but it can’t
contain multiple values of different types. For example an array of int type can only hold
integer values.

Q64) Is Java platform independent?

Yes. Java is a platform independent language. We can write java code on one platform
and run it on another platform. For e.g. we can write and compile the code on windows
and can run the generated bytecode on Linux or any other supported platform. This is one
of the main features of java.

Q65) What all memory areas are allocated by JVM?

Classloader, Class area, Heap, Stack, Program Counter Register and Native Method
Stack

Q66) Java vs. C ++?

Collected & Prepared By: T. SREENIVASULA REDDY Page 15 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

Here are the few differences between Java and C++:

● Platform dependency – C++ is platform dependent while java is platform


independent
● No goto support – Java doesn’t support goto statement while C++ does.
● Multiple inheritance – C++ supports multiple inheritance while java does
not.
● Multithreading – C++ does not have in-build thread support, on the other
hand java supports multithreading
● Virtual keyword – C++ has virtual keyword, it determines if a member
function of a class can be overridden in its child class. In java there is no
concept of virtual keyword.

Q67) Explain public static void main(String args[])

Here public is an access modifier, which means that this method is accessible by any
class.

static – static keyword tells that this method can be accessed without creating the
instance of the class. Refer: Static keyword in java

void – this main method returns no value.

main – It is the name of the method.

String args[] – The args is an array of String type. This contains the command line
arguments that we can pass while running the program.

Q68) What is javac ?

The javac is a compiler that compiles the source code of your program and generates
bytecode. In simple words javac produces the java byte code from the source code
written *.java file. JVM executes the bytecode to run the program.

Q69) What is class?

Collected & Prepared By: T. SREENIVASULA REDDY Page 16 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

A class is a blueprint or template or prototype from which you can create the object of
that class. A class has set of properties and methods that are common to its objects.

Q70) What is the base class of all classes?

java.lang.Object is the base class (super class) of all classes in java.

Q71) What is a wrapper class in Java?

A wrapper class converts the primitive data type such as int, byte, char, boolean etc. to
the objects of their respective classes such as Integer, Byte, Character, Boolean etc.
Refer: Wrapper class in Java

Q72) What is a path and classPath in Java?

Path specifies the location of .exe files. Classpath specifies the location of bytecode
(.class files).

Q73) Different Data types in Java.

● byte – 8 bit
● short – 16 bit
● char – 16 bit Unicode
● int – 32 bit (whole number)
● float – 32 bit (real number)
● long – 64 bit (Single precision)
● double – 64 bit (double precision)

Q75) What is Unicode?

Java uses Unicode to represent the characters. Unicode defines a fully international
character set that can represent all of the characters found in human languages.

Q76) What are Literals?

Any constant value that is assigned to a variable is called literal in Java. For example –

Collected & Prepared By: T. SREENIVASULA REDDY Page 17 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

// Here 101 is a literal


intnum=101

Q77) Dynamic Initialization?

Dynamic initialization is process in which initialization value of a variable isn’t known at


compile-time. It’s computed at runtime to initialize the variable.

Q78) What is Type casting in Java?

When we assign a value of one data type to the different data type then these two data
types may not be compatible and needs a conversion. If the data types are compatible (for
example assigning int value to long) then java does automatic conversion and does not
require casting. However if the data types are not compatible then they need to be casted
for conversion.

For example:

//here in the brackets we have mentioned long keyword, this is


casting
doublenum=10001.99;
long num2 =(long)num;

Q79) What is an Array?

An array is a collection (group) of fixed number of items. Array is a homogeneous data


structure which means we can store multiple values of same type in an array but it can’t
contain multiple values of different types. For example an array of int type can only hold
integer values.

Q80) What is BREAK statement in java?

The break statement is used to break the flow sequence in Java.

● break statement is generally used with switch case data structure to come out
of the statement once a case is executed.
● It can be used to come out of the loop in Java

Collected & Prepared By: T. SREENIVASULA REDDY Page 18 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

Q81) Arrays can be defined in different ways. Write them down.


intarr[];
int[]arr;

OOPs Interview Questions

Q82) Four main principles of OOPS Concepts?

● Inheritance
● Polymorphism
● Data Encapsulation
● Abstraction

Q83) What is inheritance?

The process by which one class acquires the properties and functionalities of another
class is called inheritance. Inheritance brings reusability of code in a java
application. Refer: Guide to Inheritance in Java.

Q84) Does Java support Multiple Inheritance?

When a class extends more than one classes then it is called multiple inheritance. Java
doesn’t support multiple inheritance whereas C++ supports it, this is one of the difference
between java and C++. Refer: Why java doesn’t support multiple inheritance?

Q85) What is Polymorphism and what are the types of it?

Polymorphism is the ability of an object to take many forms. The most common use of
polymorphism in OOPs is to have more than one method with the same name in a single
class. There are two types of polymorphism: static polymorphism and dynamic
polymorphism. Refer these guides to understand the polymorphism concept in detail:
1) Java Polymorphism 2) Types of Polymorphism

Q86) What is a Object class?

This is a special class defined by java; all other classes are subclasses of object class.
Object class is superclass of all other classes. Object class has the following methods

Collected & Prepared By: T. SREENIVASULA REDDY Page 19 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

● objectClone () – to creates a new object that is same as the object being


cloned.
● boolean equals(Object obj) – determines whether one object is equal to
another.
● finalize() – Called by the garbage collector on an object when garbage
collection determines that there are no more references to the object. A
subclass overrides the finalize method to dispose of system resources or to
perform other cleanup.
● toString () – Returns a string representation of the object.

Q87) What is the difference between Error and Exception?

Error: Mostly a system issue. It always occur at run time and must be resolved in order to
proceed further.
Exception: Mostly an input data issue or wrong logic in code. Can occur at compile time
or run time.

Q88) What is throws keyword?

If a method does not handle a checked exception, the method must declare it using the
throwskeyword. The throws keyword appears at the end of a method’s signature.

Q89) Can we handle more than one exception in a single catch block?

Yes we can do that using if-else statement but it is not considered as a good practice. We
should have one catch block for one exception.

Q90) What does join( ) method do?

if you use join() ,it makes sure that as soon as a thread calls join,the current
thread(yes,currently running thread) will not execute unless the thread you have called
join is finished.

Q91) What is deadlock?

Deadlock describes a situation where two or more threads are blocked forever, waiting
for each other.

Collected & Prepared By: T. SREENIVASULA REDDY Page 20 of 21


ANNAMACHARYA INSTITUTE OF TECHNOLOGY & SCIENCES :: TIRUPATHI
AUTONOMOUS
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Regulation: Subject Code: Subject Name : Object Oriented Programming AY: 2023-2024
AK20 20APC0512 Through JAVA
CSE-CIC-CSD (20APC0512/20APC3609/20APC3207)Topic Wise Interview Questions

Collected & Prepared By: T. SREENIVASULA REDDY Page 21 of 21

You might also like