Please let me know if you have any specific questions or doubts.
User
How will you call parameter less constructor, write one eg
How will you call parameterized constructor, write one eg
Can we have private constructor
Can I override constructor
Can I overload constructor
Why we can’t override constructor
How will you call parent class constructor, which doesn’t have parameters
How will you call parent class constructor, which have parameters
Assistant
To call a parameterless constructor, you simply use the name of the class to create a new object, like this:
code
MyClass obj = new MyClass();
To call a parameterized constructor, you pass the required arguments in the parentheses when creating a new object, like this:
code
MyClass obj = new MyClass(10, "John");
Yes, you can have a private constructor. A private constructor can only be called within the same class.
No, constructors cannot be overridden.
Yes, you can overload constructors by having multiple constructors with different parameter lists in the same class.
Constructors cannot be overridden because they are not inherited by subclasses. When a subclass is created, it has its own constructors and does not inherit the constructors of the superclass.
To call a parent class constructor that doesn't have parameters, you use the super() keyword in the first line of the constructor of the subclass, like this:
code
public SubClass() {
super();
// other code
}
To call a parent class constructor that has parameters, you use the super(param1, param2, ...) syntax in the first line of the constructor of the subclass, like this:
code
public SubClass(int x, String name) {
super(x, name);
// other code
}
Please let me know if you have any other questions or doubts.
User
Answer the following in JAVA
Explain oops concepts
Constructor:
How will you call parameter less constructor, write one eg
How will you call parameterized constructor, write one eg
Can we have private constructor
Can I override constructor
Can I overload constructor
Why we can’t override constructor
How will you call parent class constructor, which doesn’t have parameters
How will you call parent class constructor, which have parameters
Encapsulation:
How will you achieve encapsulation in java
Give me one scenario example where you have implemented encapsulation
What is the use of encapsulation / why do we need encapsulation
How will you hide data from external world
Can I use encapsulation for hiding data from external world
Which methods are used to achieve encapsulation
What is bean class [or] what is java bean
What is setter and getter()
Abstraction:
How will you achieve abstraction in java - which concept will you use?
Give me one real time example (not java) of abstraction?
Do you use interface or abstract class to achieve abstraction, why?
Does abstraction provide data security or code security?
Inheritance:
Can I inherit private variables of parent class in child class?
What is the use of inheritance?
Is the constructor inherited to child classes?
Are final methods inherited to child classes?
Can I call / access final methods from child class?
Can I override final methods in the child class?
How do you call a parent class constructor from a child class?
What is object class?
Can I access parent class private variables and private methods, in child class?
If i don't want to inherit my class, what should i do?
Can I inherit the final class?
What is the difference between final class and private class?
Why java doesn’t support multiple inheritance?
What is function ambiguity in java?
Show one example for function ambiguity.
How will you achieve multiple inheritance in java? Show one eg?
How many types of inheritances are there in java?
Which keyword do you use for inheritance?
What is the limitation or disadvantage of inheritance in java.
Polymorphism:
Give one example for static polymorphism
Give one example for dynamic polymorphism
Show code for achieving dynamic polymorphism
Method overloading
Assistant
OOPS concepts:
Object-Oriented Programming (OOP) is a programming paradigm that is based on the concept of objects, which can contain data and methods.
Constructor:
To call a parameterless constructor, you simply use the name of the class to create a new object, like this:
code
MyClass obj = new MyClass();
To call a parameterized constructor, you pass the required arguments in the parentheses when creating a new object, like this:
code
MyClass obj = new MyClass(10, "John");
Yes, you can have a private constructor. A private constructor can only be called within the same class.
No, constructors cannot be overridden.
Yes, you can overload constructors by having multiple constructors with different parameter lists in the same class.
Constructors cannot be overridden because they are not inherited by subclasses.
To call a parent class constructor that doesn't have parameters, you use the super() keyword in the first line of the constructor of the subclass, like this:
code
public SubClass() {
super();
// other code
}
To call a parent class constructor that has parameters, you use the super(param1, param2, ...) syntax in the first line of the constructor of the subclass, like this:
code
public SubClass(int x, String name) {
super(x, name);
// other code
}
Encapsulation:
Encapsulation in Java is achieved by using access modifiers such as private, protected and public to restrict access to the fields and methods of a class.
One scenario where encapsulation is used is in a banking application, where sensitive information such as account numbers and passwords are kept private and can only be accessed by authorized methods.
Encapsulation is used to protect the data and methods of a class from external access, ensuring data integrity and security.
Data can be hidden from the external world by using the private access modifier for fields and methods.
Yes, encapsulation can be used to hide data from the external world.
The private access modifier is used to achieve encapsulation.
A Java Bean is a Java class that follows certain conventions, such as having a default constructor and getter and setter methods for its properties.
User
Inheritance:
Can I inherit private variables of parent class in child class?
What is the use of inheritance?
Is the constructor inherited to child classes?
Are final methods inherited to child classes?
Can I call / access final methods from child class?
Can I override final methods in the child class?
How do you call a parent class constructor from a child class?
What is object class?
Can I access parent class private variables and private methods, in child class?
If i don't want to inherit my class, what should i do?
Can I inherit the final class?
What is the difference between final class and private class?
Why java doesn’t support multiple inheritance?
What is function ambiguity in java?
Show one example for function ambiguity.
How will you achieve multiple inheritance in java? Show one eg?
How many types of inheritances are there in java?
Which keyword do you use for inheritance?
What is the limitation or disadvantage of inheritance in java.
Assistant
Inheritance:
No, private variables of a parent class cannot be inherited by a child class because they have private access level.
Inheritance allows for code reuse and creates a hierarchy of classes where a child class can inherit properties and methods from a parent class.
Constructors are not inherited by child classes, a child class has its own constructors and must use the super() keyword to call the parent class constructor.
Final methods are inherited by child classes, but they cannot be overridden by the child class.
Final methods can be called from a child class, but they cannot be overridden.
Final methods cannot be overridden by a child class.
A parent class constructor is called from a child class using the super() keyword in the first line of the child class constructor.
Object is a class in Java that is the superclass of all other classes.
Private variables and methods of a parent class cannot be accessed by a child class because they have private access level.
To prevent a class from being inherited, the class can be declared as final or its constructor can be made private.
A final class cannot be inherited by other classes.
A private class can only be accessed within the same package and cannot be inherited by other classes. A final class can be inherited but its methods cannot be overridden.
Java doesn't support multiple inheritance to avoid ambiguity and complexity that may arise from multiple inheritance.
Function ambiguity occurs when a child class inherits methods with the same name and signature from multiple parent classes.
An example of function ambiguity is when a child class inherits two methods with the same name and signature, one from parent class A and one from parent class B, and the child class doesn't specify which method to use.
Multiple inheritance can be achieved in Java using interfaces. A class can implement multiple interfaces but can only extend one class.
In Java, there is only one type of inheritance which is class inheritance.
The keyword "extends" is used for inheritance in Java.
One limitation of inheritance in Java is that a class can only extend one class, so multiple inheritance is not directly supported. Additionally, a subclass can only inherit the properties and methods of its parent class, but not their implementation.
User
Explain in JAVA
Polymorphism:
Give one example for static polymorphism
Give one example for dynamic polymorphism
Show code for achieving dynamic polymorphism
Method overloading
Public void f1() {} — public int f1() {return 10;} is it overloading
Can i overload constructor
Can i overload static methods
Can i overload final methods
How will you call overloaded methods, eg.
Method overriding:
Can i override private methods of parent class in child class
Can i override abstract methods in child class
Can i override parent class constructor in child class, why?
If I don't want to override a parent class method in child class, what should i do?
What is the difference between private method and final method (as we can’t override
both methods in child class)?
Can i override parent class static methods
Which type of polymorphism you can achieve with method overriding
Assistant
Polymorphism:
Static polymorphism, also known as compile-time polymorphism, is achieved through method overloading. An example of static polymorphism is having multiple methods with the same name but different parameters in the same class.
code
class MyClass {
public void print(int x) {
System.out.println(x);
}
public void print(double x) {
System.out.println(x);
}
}
Dynamic polymorphism, also known as runtime polymorphism, is achieved through method overriding. An example of dynamic polymorphism is having a parent class and a child class with a method with the same name and signature, and the child class overrides the parent class method.
code
class Parent {
public void print() {
System.out.println("Parent class");
}
}
class Child extends Parent {
@Override
public void print() {
System.out.println("Child class");
}
}
You can achieve dynamic polymorphism by using a reference variable of a parent class to refer to an object of a child class. The parent class reference variable can call the overridden method of the child class at runtime.
code
Parent obj = new Child();
obj.print(); // Output: "Child class"
Method overloading:
Yes, the two methods public void f1() and public int f1() are considered method overloading because they have the same method name but different parameter lists.
Yes, you can overload constructors in a class by having multiple constructors with different parameter lists.
Yes, you can overload static methods in a class by having multiple methods with the same name but different parameter lists.
No, final methods cannot be overloaded because they cannot be overridden.
To call an overloaded method, you need to use the correct method signature that corresponds to the parameters passed in the method call.
Method overriding:
No, private methods of a parent class cannot be overridden by a child class because they have private access level.
Yes, a child class can override the abstract methods of its parent class.
No, parent class constructors cannot be overridden by a child class.
To prevent a parent class method from being overridden by a child class, the method can be declared as final.
A private method can only be accessed within the same class, while a final method can be accessed by other classes but cannot be overridden.
No, parent class static methods cannot be overridden by a child class.
User
Which type of polymorphism you can achieve with method overriding
Assistant
The type of polymorphism that can be achieved with method overriding is dynamic polymorphism, also known as runtime polymorphism. This is because, during runtime, the JVM (Java Virtual Machine) determines which version of an overridden method to call based on the type of the object being referred to by the reference variable.
User
Static and non static:
How will you access static variables of a class? Show one eg
How will you access non static variables of a class? Show one eg
Which is faster, static methods or instance methods. Why?
Why is the main() method static?
Can I access non-static variables inside a static method?
What is the difference between static methods and instance methods?
Assistant
Static and non-static:
You can access static variables of a class by using the class name and the dot (.) operator, like this:
code
MyClass.staticVar;
You can access non-static variables of a class by creating an instance of the class and using the dot (.) operator, like this:
code
MyClass obj = new MyClass();
int x = obj.nonStaticVar;
Static methods are generally faster than instance methods because they are invoked using the class name and don't require an instance of the class to be created.
The main() method is static because it is the entry point of a Java program and needs to be called before any objects are created.
No, you cannot access non-static variables inside a static method because a static method does not have access to the instance variables of a class.
Static methods are methods that are associated with a class and can be called using the class name, whereas instance methods are associated with an object and can be called using an object reference. Static methods can only access static variables and call other static methods, whereas instance methods can access both static and non-static variables and call both static and instance methods.
User
Abstract methods and abstract classes:
If I have 0 abstract methods in a class, can I make that class an abstract class?
Can I create an object for an abstract class?
How will you access methods of an abstract class?
When will you use an abstract class, give one scenario with code
(same question can be asked as what is the use of abstract class)
When will you use an abstract method, give one scenario with code
(same question can be asked as what is the use of abstract method)
Can I achieve complete or full abstraction with the help of abstract class? Why if not?
Can I make an abstract class as a final class?
Give one real time example (not java) of abstract class.
Assistant
Abstract methods and abstract classes:
No, a class must have at least one abstract method to be considered an abstract class.
No, you cannot create an object for an abstract class because it is meant to be a base class and cannot be instantiated.
You can access methods of an abstract class by creating an instance of a concrete (non-abstract) subclass that extends the abstract class.
An abstract class can be used as a base class for other classes, where the abstract class contains common properties and methods that should be shared among its subclasses. An example of this is a shape class that contains a method for calculating the area, and then having concrete classes such as Square and Circle that extend the shape class and implement the method for calculating the area specific to their shapes.
code
abstract class Shape {
public abstract double getArea();
}
class Square extends Shape {
private double side;
public Square(double side) {
this.side = side;
}
@Override
public double getArea() {
return side * side;
}
}
An abstract method is used when a base class wants to provide a method signature but doesn't want to provide an implementation. This is so that subclasses can provide their own implementation of the method. An example of this is a shape class that contains an abstract method draw(), and then having concrete classes such as Square and Circle that extend the shape class and implement the method draw() specific to their shape.
code
abstract class Shape {
public abstract void draw();
}
class Square extends Shape {
@Override
public void draw() {
//draw a square
}
}
No, it is not possible to achieve complete or full abstraction with the help of abstract class because an abstract class can contain both abstract methods and concrete methods.
No, an abstract class cannot be a final class because a final class cannot be extended.
An example of an abstract class in real life is a vehicle class. It contains some common properties like number of wheels, weight and some common methods like start, stop, accelerate, brake etc. However, it doesn't make sense to create an object of the vehicle class, because it doesn't specify what type of vehicle it is. Instead, we would create objects of subclasses of the vehicle class such as car, bike, truck etc.
User
Interface:
What is the use of interface (same question can be asked as when will you use
interface) give one scenario example with code
Does interface support multiple inheritance, show code
How will you achieve multiple inheritance with interfaces
How will you use interface
What is the access specifier used for the members of interfaces?
Can we achieve complete or full abstraction with an interface? Why
Can I implement multiple interfaces in a class?
Give one real world example (not java) of interface?
Assistant
Interface:
An interface is used to define a contract for a set of methods that a class must implement. This allows for loose coupling between classes and promotes the principle of "programming to an interface." An example of this is a shape interface that contains a method for calculating the area, and then having concrete classes such as Square and Circle that implement the shape interface and provide their own implementation of the method for calculating the area specific to their shapes.
code
interface Shape {
double getArea();
}
class Square implements Shape {
private double side;
public Square(double side) {
this.side = side;
}
@Override
public double getArea() {
return side * side;
}
}
Yes, interfaces in Java support multiple inheritance. You can implement multiple interfaces in a class by using the keyword "implements" followed by the interface names.
code
interface Shape {
double getArea();
}
interface Printable {
void print();
}
class Square implements Shape, Printable {
private double side;
public Square(double side) {
this.side = side;
}
@Override
public double getArea() {
return side * side;
}
@Override
public void print() {
System.out.println("Square with side " + side);
}
}
You can achieve multiple inheritance with interfaces by a class implementing multiple interfaces.
You can use an interface by creating an instance of a concrete class that implements the interface and then calling the methods defined in the interface.
The access specifier used for the members of interfaces is "public" by default.
Yes, interfaces can be used to achieve complete or full abstraction because all the methods in an interface are abstract by default and must be implemented by the class that implements the interface.
Yes, a class can implement multiple interfaces in Java.
An example of an interface in the real world is a remote control. It defines a set of buttons and their functionality (volume up, volume down, power on/off etc.) that any electronic device that wants to be controlled remotely must implement.
User
Access specifier:
Can I access protected variables in other packages?
Can I access private variables in other classes?
Which access specifier is used for data security?
Difference bw protected and default
Assistant
Access specifiers:
Protected variables can be accessed within the package in which it is defined and also in the subclasses of other packages.
Private variables can only be accessed within the same class in which it is defined.
The private access specifier is used for data security because it restricts access to the variable to only the class in which it is defined, making it not accessible from other classes.
The protected access specifier allows access within the package and also in subclasses of other packages, whereas the default access specifier allows access within the package only.
User
Exceptions:
What is checked exception
What is unchecked exception
Give one eg for checked and unchecked exception
If i don't want to handle an exception, what should i do
If I use throws, and if an exception occurs in the current method, then what will happen.
Who is going to handle that exception?
What is the use of throw
How will you create custom exception
What happens if an exception occurs in the finally block? Will the finally block be
executed?
If we use system.exit(), then finally block will be executed or not?
Assistant
Exceptions:
Checked exceptions are exceptions that are checked by the compiler at compile-time. These are exceptions that are expected to occur and must be handled or declared using a try-catch block or the throws keyword in the method signature.
Unchecked exceptions are exceptions that occur at runtime and are not checked by the compiler. These are also known as runtime exceptions. Examples include NullPointerException, ArrayIndexOutOfBoundsException.
An example of a checked exception is FileNotFoundException, which occurs when a file is not found and must be handled or declared using a try-catch block or the throws keyword in the method signature. An example of an unchecked exception is NullPointerException, which occurs when an application attempts to use a null object reference and doesn't need to be handled or declared.
If you don't want to handle an exception, you can use the throws keyword in the method signature to propagate the exception to the calling method.
If an exception occurs in the current method and the method uses the throws keyword, the exception will be propagated to the calling method and the calling method will be responsible for handling the exception.
The "throw" keyword is used to throw an exception manually in the code, rather than having the exception occur automatically.
You can create a custom exception by creating a new class that extends the Exception class or one of its subclasses, and then throwing an instance of that class in the appropriate place
User
How will you create custom exception
What happens if an exception occurs in the finally block? Will the finally block be
executed?
If we use system.exit(), then finally block will be executed or not?
Assistant
Exceptions:
7. To create a custom exception, you can create a new class that extends the Exception class or one of its subclasses. For example:
code
class MyException extends Exception {
public MyException(String message) {
super(message);
}
}
If an exception occurs in the finally block, the finally block will still be executed. However, the exception will not be handled in the finally block and will be propagated to the calling method.
If the System.exit() method is used, the program will exit immediately, and any remaining code, including any code in the finally block, will not be executed.
User
Collections & generics:
What is the use of collections
How will you store 10, “ramesh”, 10.5 without using class and without using 3 variables.
What is the difference between Object[] array and collections
In which version java collections are introduced
What is the difference between collections and generics
Why generics are safe
Which one is faster, collections or generics
difference between linked list and array list which is best
When will you use linked list (in what cases linked is faster)
If linked list is slow why should I use
dif bw list and set [or] arraylist vs set
dif bw set and map
dif bw array and list
Assistant
Collections & Generics:
Collections are used to store, retrieve, and manipulate a group of related objects. They provide a way to handle a group of objects as a single unit, such as adding, removing, or searching for an object in a collection.
One way to store 10, "ramesh", and 10.5 without using a class and without using 3 variables is to use an ArrayList:
code
ArrayList<Object> list = new ArrayList<>();
list.add(10);
list.add("ramesh");
list.add(10.5);
The main difference between an Object[] array and a collection is that a collection is an object that can grow or shrink dynamically, whereas an array has a fixed size. Collections also provide additional methods for manipulating the group of objects, such as sorting and searching.
Java collections were introduced in version 1.2 of the Java Development Kit (JDK).
Collections are a set of classes and interfaces that are used to store and manipulate a group of related objects, whereas generics are a feature added in Java 5 that allow for type safety and type checking at compile-time.
Generics are safe because they allow for type safety and type checking at compile-time, which helps to prevent runtime errors caused by casting and type mismatches.
The performance of collections and generics is generally similar, but in some specific cases, collections may be slightly faster due to less overhead.
ArrayList and LinkedList are both implementations of the List interface, but an ArrayList is backed by an array and provides constant-time performance for the basic operations (get and set), while a LinkedList is backed by a doubly-linked list and provides constant-time performance for add and remove operations at the beginning and end of the list. ArrayList is best when you have to perform a lot of get and set operations, while LinkedList is best when you have to perform a lot of add and remove operations.
LinkedList is best when you have to perform a lot of add and remove operations at the beginning and end of the list, such as in a queue or stack.
10
User
When will you use linked list (in what cases linked is faster)
If linked list is slow why should I use
dif bw list and set [or] arraylist vs set
dif bw set and map
dif bw array and list
Assistant
Even though a LinkedList may have slower performance than an ArrayList when it comes to random access, it can be useful in situations where you need to frequently add or remove elements from the list, especially at the beginning or end of the list. LinkedList also uses less memory than an ArrayList with the same number of elements, because it doesn't need to maintain an internal array with spare capacity.
A List is an ordered collection of elements, it allows duplicates, and it has a specific order. A Set is a collection of unique elements, it doesn't allow duplicates, and the order of elements is not guaranteed to be consistent. In other words, ArrayList is a List implementation that allows duplicates and maintains the order of elements, while a Set is a collection that doesn't allow duplicates.
A Set is a collection of unique elements, it doesn't allow duplicates, and the order of elements is not guaranteed to be consistent. A Map is a collection that maps keys to values, it doesn't allow duplicate keys, and the order of elements is not guaranteed to be consistent.
An array is a basic data structure that stores a fixed-size, homogeneous collection of elements. A List is an ordered collection of elements that allows duplicates and has specific order. An array is a basic data structure that is built into the language, whereas a List is a part of the Java Collections Framework.
User
Memory, garbage collection, threads and miscellaneous:
How many parts are there in memory
What is stored in stack
What is stored in heap
What is garbage collector
What is the meaning of un referenced objects
What is hashcode
What is synchronization
What is thread priority
What is main thread
What is set priority
What is jre vs jdk
What is the use of stack heap
What is current version of java
What is clone()
what is serializable interface
== vs equals()
Assistant
Memory, garbage collection, threads and miscellaneous:
The memory of a Java program is divided into two parts: the heap and the stack.
The stack is a memory area that stores local variables and function call information. It stores information about the current state of a thread, including the values of local variables and the call stack.
The heap is a memory area that stores objects and their associated data. It is a shared memory area where all threads can access objects.
The garbage collector is a Java process that automatically frees up memory by removing objects that are no longer being used by the program.
Unreferenced objects are objects that no longer have any references pointing to them and are eligible to be garbage collected.
A hashcode is a unique integer value that is assigned to an object. It is used to quickly identify and compare objects in a collection, such as a HashSet or HashMap.
Synchronization is a technique used to ensure that only one thread can access a shared resource at a time. It is used to prevent race conditions and other synchronization-related issues.
Thread priority is a value that determines the order in which threads are executed by the Java Virtual Machine (JVM). A thread with a higher priority will be executed before a thread with a lower priority.
The main thread is the first thread that is started when a Java program is executed. It is responsible for executing the main() method.
The setPriority() method is used to set the priority of a thread. It takes an integer value between MIN_PRIORITY (1) and MAX_PRIORITY (10) as an argument.
JRE (Java Runtime Environment) is a software package that contains the Java Virtual Machine (JVM), the Java class libraries, and other components necessary to run Java programs. JDK (Java Development Kit) is a software development kit that
User
What is jre vs jdk
What is the use of stack heap
What is current version of java
What is clone()
what is serializable interface
== vs equals()
Assistant
JRE (Java Runtime Environment) is a software package that contains the Java Virtual Machine (JVM), the Java class libraries, and other components necessary to run Java programs. JDK (Java Development Kit) is a software development kit that includes the JRE, as well as tools for developing, debugging, and deploying Java applications.
The stack is used for storing method call frames and local variables, while the heap is used for storing objects. The stack memory is used to store data that is in the process of being executed, while heap memory is used to store data that will be used in the future.
The current version of Java is Java SE 15 as of September, 2021.
The clone() method is used to create a copy of an object. It creates a new object with the same values as the original object.
The Serializable interface is a marker interface that is used to indicate that an object can be serialized. Serialization is the process of converting an object's state to a byte stream, which can then be stored or transmitted.
The == operator compares the memory addresses of two objects to determine if they are the same. The equals() method compares the contents of two objects to determine if they are equal. In general, it's more appropriate to use the equals() method when comparing objects for equality.
Public void f1() {} — public int f1() {return 10;} is it overloading
Can i overload constructor
Can i overload static methods
Can i overload final methods
How will you call overloaded methods, eg.
Method overriding:
Can i override private methods of parent class in child class
Can i override abstract methods in child class
Can i override parent class constructor in child class, why?
If I don't want to override a parent class method in child class, what should i do?
What is the difference between private method and final method (as we can’t override
both methods in child class)?
Can i override parent class static methods
Which type of polymorphism you can achieve with method overriding
Static and non static:
How will you access static variables of a class? Show one eg
How will you access non static variables of a class? Show one eg
Which is faster, static methods or instance methods. Why?
Why is the main() method static?
Can I access non-static variables inside a static method?
What is the difference between static methods and instance methods?
Abstract methods and abstract classes:
If I have 0 abstract methods in a class, can I make that class an abstract class?
Can I create an object for an abstract class?
How will you access methods of an abstract class?
When will you use an abstract class, give one scenario with code
(same question can be asked as what is the use of abstract class)
When will you use an abstract method, give one scenario with code
(same question can be asked as what is the use of abstract method)
Can I achieve complete or full abstraction with the help of abstract class? Why if not?
Can I make an abstract class as a final class?
Give one real time example (not java) of abstract class.
Interface:
What is the use of interface (same question can be asked as when will you use
interface) give one scenario example with code
Does interface support multiple inheritance, show code
How will you achieve multiple inheritance with interfaces
How will you use interface
What is the access specifier used for the members of interfaces?
Can we achieve complete or full abstraction with an interface? Why
Can I implement multiple interfaces in a class?
Give one real world example (not java) of interface?
Access specifier:
Can I access protected variables in other packages?
Can I access private variables in other classes?
Which access specifier is used for data security?
Difference bw protected and default
Exceptions:
What is checked exception
What is unchecked exception
Give one eg for checked and unchecked exception
If i don't want to handle an exception, what should i do
If I use throws, and if an exception occurs in the current method, then what will happen.
Who is going to handle that exception?
What is the use of throw
How will you create custom exception
What happens if an exception occurs in the finally block? Will the finally block be
executed?
If we use system.exit(), then finally block will be executed or not?
Collections & generics:
What is the use of collections
How will you store 10, “ramesh”, 10.5 without using class and without using 3 variables.
What is the difference between Object[] array and collections
In which version java collections are introduced
What is the difference between collections and generics
Why generics are safe
Which one is faster, collections or generics
difference between linked list and array list which is best
When will you use linked list (in what cases linked is faster)
If linked list is slow why should I use
dif bw list and set [or] arraylist vs set
dif bw set and map
dif bw array and list
Memory, garbage collection, threads and miscellaneous:
How many parts are there in memory
What is stored in stack
What is stored in heap
What is garbage collector
What is the meaning of un referenced objects
What is hashcode
What is synchronization
What is thread priority
What is main thread
What is set priority
What is jre vs jdk
What is the use of stack heap
What is current version of java
What is clone()
what is serializable interface
== vs equals(
Setter and getter methods, also known as accessor and mutator methods, are used to set and get the values of the properties of a class.
Abstraction:
Abstraction in Java is achieved by using abstract classes and interfaces.
An example of abstraction in real life is a remote control. It has buttons with different functions, but the user doesn't need to know how it works internally.
An interface is used when you want to define a set of methods that need to be implemented by multiple classes, while an abstract class can have both abstract and concrete methods.
Abstraction does not provide data or code security, it is used to hide the implementation details of a class and provide a simplified interface to the user.
Inheritance:
No, private variables of a parent class cannot be inherited by a child class.
Inheritance is used to create a hierarchy of classes, where a child class inherits properties and methods from a parent class.
No, constructors are not inherited by child classes.