Java Commonly Asked Interview Questions
Java Commonly Asked Interview Questions
Java Commonly Asked Interview Questions
Local variables are defined in the method and scope of the variables that have existed
inside the method itself. An instance variable is defined inside the class and outside the
method and scope of the variables exist throughout the class.
7) What is Inheritance?
Inheritance means one class can extend to another class. So that the codes can be
reused from one class to another class.
Existing class is known as Super class whereas the derived class is known as a sub
class.
8) What is Polymorphism?
Polymorphism means many forms.
A single object can refer the super class or sub-class depending on the reference type
which is called polymorphism.
9) What is meant by Method Overriding?
Method overriding happens if the sub class method satisfies the below
conditions with the Super class method:
Method name should be same
Argument should be same
Return type also should be same
The key benefit of overriding is that the Sub class can provide some specific information
about that sub class type than the super class.
All the methods in the interface are internally public abstract void.
All the variables in the interface are internally public static final that is constants.
Classes can implement the interface and not extends.
The class which implements the interface should provide an implementation for
all the methods declared in the interface.
12) What is meant by Abstract class?
We can create the Abstract class by using “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 are the ends with
a semicolon.
Once the run() method has completed, then JVM switches back to the main thread and the
User thread has completed the task and the stack was disappeared.
JVM switches between each thread until both the threads are completed. This is called
Multi-threading.
In Java, it is possible to inherit attributes and methods from one class to another. We group
the "inheritance concept" into two categories:
Polymorphism means "many forms", and it occurs when we have many classes
that are related to each other by inheritance.
Data abstraction is the process of hiding certain details and showing only essential
information to the user.
Abstraction can be achieved with either abstract classes or interfaces (which you will
learn more about in the next chapter).
The abstract keyword is a non-access modifier, used for classes and methods:
Abstract class: is a restricted class that cannot be used to create objects (to access
it, it must be inherited from another class).
Abstract method: can only be used in an abstract class, and it does not have a
body. The body is provided by the subclass (inherited from).