OOPs: Polymorphism, Abstraction and Package interview questions

本文详细探讨了Java中的面向对象编程(OOPs)核心概念,包括多态、抽象和包等内容。解释了运行时多态的概念,并讨论了抽象类与接口的区别,为读者提供了深入理解Java OOPs的基础。

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...

转载于:https://www.cnblogs.com/vicky-project/p/9350578.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值