Grokking The Java Developer Interview: More Than 200 Questions To Crack The Java, Spring, SpringBoot & Hibernate Interview


Question 4: What is an Interface?



Download 7,31 Mb.
Pdf ko'rish
bet5/89
Sana21.04.2022
Hajmi7,31 Mb.
#571320
1   2   3   4   5   6   7   8   9   ...   89
Bog'liq
Grokking-The-Java-Developer-Interview-More-Than-200-Questions-To-Crack-The-Java -Spring -SpringBoot-

Question 4: What is an Interface?
Answer:
An interface in Java is a blueprint of a class. It has static
constants and abstract methods.
Interface specify what a class must do but not how to do
An interface is like defining a contract that is fulfilled by
implementing classes
An interface is used to achieve full abstraction.
All methods in an interface are public and abstract by
default and all variables declared in an interface are
constants i.e. public, static and final
A class which implements an interface will have to
provide implementation of all the methods that are
defined in the interface
A class can implement more than one interface, this is
how Java allows multiple inheritance.
Since Java 8, we can have default and static methods in
an interface
Question 5: Difference between abstract class and
interface
Answer: The differences are:


Abstract class can have both abstract and concrete
methods but interface can only have abstract methods
(Java 8 onwards, it can have default and static methods
as well)
Abstract class methods can have access modifiers other
than public but interface methods are implicitly public
and abstract
Abstract class can have final, non-final, static and non-
static variables but interface variables are only static and
final
A subclass can extend only one abstract class but it can
implement multiple interfaces
An Abstract class can extend one other class and can
implement multiple interfaces but an interface can only
extend other interfaces
In this question, the interviewer may try to confuse you by saying
that from Java 8 onwards, you can have static and default methods
in an Interface so now what is the difference between abstract class
and interface and the answer you should tell is – We can still extend
only one class but can implement multiple interfaces.

Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   89




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish