trainingtrains Logo

91-9990449935

 0120-4256464

OOPs: Polymorphism, Abstraction and Package interview questions


1 2 3 4 5 6 7 8

Core Java - OOPs : Polymorphism Interview Questions


53) What is Runtime Polymorphism?

Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time.

In this process, an overridden method is called through the reference variable of a super class. The determination of the method to be called is based on the object being referred to by the reference variable.

more details...

54) Can you achieve Runtime Polymorphism by data members?

No.

more details...

55) What is the difference between static binding and dynamic binding?

In case of static binding type of object is determined at compile time whereas in dynamic binding type of object is determined at runtime.

more details...

Core Java - OOPs Concepts : Abstraction Interview Questions


56) What is abstraction?

Abstraction is a process of hiding the implementation details and showing only functionality to the user.

more details...

Abstraction lets you focus on what the object does instead of how it does it.


57) What is the difference between abstraction and encapsulation?

Abstraction hides the implementation details whereas encapsulation wraps code and data into a single unit.

more details...

58) What is abstract class?

A class that is declared as abstract is known as abstract class. It needs to be extended and its method implemented. It cannot be instantiated.

more details...

59) Can there be any abstract method without abstract class?

No, if there is any abstract method in a class, that class must be abstract.


60) Can you use abstract and final both with a method?

No, because abstract method needs to be overridden whereas you can't override final method.


61) Is it possible to instantiate the abstract class?

No, abstract class can never be instantiated.


62) What is interface?

Interface is a blueprint of a class that have static constants and abstract methods.It can be used to achieve fully abstraction and multiple inheritance.

more details...

63) Can you declare an interface method static?

No, because methods of an interface is abstract by default, and static and abstract keywords can't be used together.


64) Can an Interface be final?

No, because its implementation is provided by another class.


65) What is marker interface?

An interface that have no data member and method is known as a marker interface.For example Serializable, Cloneable etc.


66) What is difference between abstract class and interface?

Abstract classInterface
1)An abstract class can have method body (non-abstract methods). Interface have only abstract methods.
2)An abstract class can have instance variables.An interface cannot have instance variables.
3)An abstract class can have constructor.Interface cannot have constructor.
4)An abstract class can have static methods.Interface cannot have static methods.
5)You can extends one abstract class.You can implement multiple interfaces.

67) Can we define private and protected modifiers for variables in interfaces?

No, they are implicitly public.


68) When can an object reference be cast to an interface reference?

An object reference can be cast to an interface reference when the object implements the referenced interface.


Core Java - OOPs Concepts : Package Interview Questions


69) What is package?

A package is a group of similar type of classes interfaces and sub-packages. It provides access protection and removes naming collision.

more details...

70) Do I need to import java.lang package any time? Why ?

No. It is by default loaded internally by the JVM.


71) Can I import same package/class twice? Will the JVM load the package twice at runtime?

One can import the same package or same class multiple times. Neither compiler nor JVM complains about it.But the JVM will internally load the class only once no matter how many times you import the same class.


72) What is static import ?

By static import, we can access the static members of a class directly, there is no to qualify it with the class name.

more details...



1 2 3 4 5 6 7 8