#66 What is Interface in Java

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

Udemy Courses:

For More Queries WhatsApp or Call on : +919008963671

In this lecture we will learn:
- What is an interface in java?
- Use of interface
- implements keyword in an interface
- Variables in an interface

#1
Interface:-
In an abstract class, we can have both abstract methods as well as normal or concrete methods.
- If your class has only abstract methods then instead of using class, you can simply use an interface in place of it.
- Interface is not any class.
- Every method in an interface is public and abstract by default.
- Even if you do not use two keywords (public and abstract) with methods then also it will not give an error in an interface. By default, it will consider all methods as public and abstract.
- We cannot instantiate an interface.
- Interface only shows the design and it does not provide any implementation.
- To provide an implementation of methods, you need to create a class and instantiate it also.
e.g,
interface A
{
methods()----
}

#2
implements keyword:-
To implement an interface, we use the keyword - implements.
- If you use the implements keyword with class, then it is compulsory to give an implementation of all the methods that are defined in an interface.
- If you do not give an implementation of all methods then it will make your class an abstract class by default.
- So, to make a concrete class, you have to give the implementation of all methods present in an interface.
e.g.,
class B implements A
{
methods() {
statement;
}
------
}

#3
Variables in an interface:-
- We can call the methods of an interface by creating an object of the class that implements an interface.
- We can also declare variables in an interface.
- All the variables in an interface are final and static by default.
- So, we first have to initialize the variables in an interface.
- As a variable is static in an interface, then you do not need to create an object for it. You can directly call the variable by using the interface name.
e.g., A.area; (here, area is a variable initialized in an interface)
- As the variable is final, you can not change the value of that variable after initializing it once.

-Interface does not have its own memory in the heap.

More Learning :

Donation:
PayPal Id : navinreddy20
Рекомендации по теме
Комментарии
Автор

Today I subscribed you after watching this video. Your explanation and English pronouncing are better than others. I respect you my new Teacher ❤. Love from Sri Lanka

thusith-tec
Автор

Your Process of explaining and the step by step developed example is just blowing my minds. Tomorrow is my java final exam. I have regrate that why I didn't follow you from before! Your teaching system is well pre-planed, clear.
I have a request, plz don't stop making tutorial. Keep doing by this way of explaining. Need Python, framework, Algorithm from you.

jibonjibon
Автор

At 7:26 it is said that "we are doing implement not extends so only methods are available and variables are not available". Actually, regardless of what we do implementation of interface or extends of parent class, the variables also gets passed on in child. When we do Subclass obj = new Subclass(); we can see that variables are accessible. The thing with interface is that as the variables are final, so we can't change it. But it is available in child class! Maybe it was just Slip of tongue by Telusko!

Enjoying the series so much! Thank you for posting it!❤

DeeperRed-ofgp
Автор

Amezing explination everyone saying only theory u are the only one following practical manner ur having great explanation

ramyapinapothu
Автор

I have been watching Navin sirs old vedios and found this gem ....good to know you are doing well....looking fresh sir ✨ with an upgrade

obaldalmeida
Автор

Great playlist! There are some other videos in this course playlist that explain the terms used in this one. Feel free to give them a look if you're in need of a quick refresh!

rapidken
Автор

What a type of teaching skills ! Mind-blowing

projyoti
Автор

Hi @Telusko thank you very much for all those wonderful videos. Just started learning java and I am already learning alot. Have a quick question for you, while doing PHP we used to write interfaces for the model entity class, what do you think about it? what might be the pros and cons?

AmarGrg
Автор

I read Interface through a book but I couldn't understand it, until I found your video. Thanks

daulitech
Автор

Video #66. and #65 should be interchanged, i.e, explain what is an interface and then explain why it is important. It will be easier to understand.

adityasrinivas
Автор

Can someone tell me why inside println(), "x:" is used. This variable "x" is not declared anywhere and is not giving any error. Also if it is not a variable then let me know what it is.

srimantamondal
Автор

Are we take scanner (input) at the time of declaring any variables inside the interface.?

adityamishra_
Автор

Why this error come - failed to resolve main method code lens :inter faceis not a valid java identifier

sushmithakn
Автор

Can i implement another method in class B

filmbuzz
Автор

Notes:
All variables inside interface are static and final

raghavsood