Java Interface | Java tutorials for beginners

Veröffentlicht am: 22 Februar 2023
auf dem Kanal: SG Tutorial
1,624
27

Java Interface | Java tutorials for beginners
About this Video:
This video will explain basics of Java interface with real life example as well as practical example.
Links:
To learn about basics of Java click here 👇
Java Basics:    • Java Tutorials for Beginners | Java course...  
Java Abstraction:
   • Java Abstraction | Java tutorials for begi...  
Method Overriding:
   • Method Overriding in Java | Java Method Ov...  
Notes:
1) What is Interface?
2) Uses of Interface.
3) Syntax
4) Achive abstraction by interface.
1) What is Interface?
First, let's understand in real life scenario,
Suppose,you have to make a wooden chair by the help of carpenter.
So for that, first,you will need to give details about chair or we can say specifications about chair to the carpenter and specifications such as suppose,
designOfChair();
sizedOfChair() ;
applyColor();
And using this specifications carpenter will make a chair as per your requirement
I .e carpenter will use or implement all these specifications while making chair..
So, these are the Requirement specification
And these Requirement specifications we can called an interface..
So if we think technically,
Here, you are a client demanding for wooden chair and carpenter will be a service provider who providing service by implementing all these specifications to make a chair as per your requirement..
so here we can say ,
this interface is work like an agreement or contract
between you and carpenter
I.e between client and service provider..
So basically,
Interface can be define as : Any agreement or contract between client and service provider.
2) Uses of Interface:
i)Interface is used to achieve total abstraction.
ii)Interface is used to achieve multiple inheritance.
iii)Interface is used to achieve Loose coupling.
3) Syntax:
interface Interface Name
{
// constant fields;
// abstract methods;
(features added under
👇 Java version 8)
// default methods ;
// static methods;
(features added under
👇Java version 9)
//private methods;
// private static methods;
}
4) Achive abstraction by interface:
interface User{
void insertCard();
void enterPin();
}
class Test1 implements User {
public void insertCard(){
System.out.println("Please insert card.");
}
public void enterPin(){
System.out.println("Please enter a pin.");
}
}
class Test {
public static void main(String [ ] args){
Test1 test1Obj = new Test1();
test1Obj.insertCard();
test1Obj.enterPin();
}
Output:
Please insert card.
Please enter a pin.

#javainterface #interfaceinjava #javainterfacewithnotes #sgturorial #javainterfacewithreallifeexample #javainterfacewithexample #javainterfacenewfeatures


Auf dieser Seite können Sie das Online-Video Java Interface | Java tutorials for beginners mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer SG Tutorial 22 Februar 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,624 Mal angesehen und es wurde von 27 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!