RUVIDEO
Поделитесь видео 🙏

java 31 | Extending Interfaces | Accessing interface fields

📁 Лайфстайл 👁️ 16 📅 05.12.2023

In this class we are going to talk about inheriting interfaces and accessing inheritance fields.
A class can inherit multiple interfaces but not multiple classes
An interface can also inherit multiple interfaces
Multiple inheritance is not supported through class in java, but it is possible by an interface, why?
multiple inheritance is not supported in the case of class because of ambiguity. However, it is supported in case of an interface because there is no ambiguity.
It is because its implementation is provided by the implementation class

interface Printable{  
void print();  
}  
interface Showable{  
void print();  
}  
class TestInterface2 implements Printable, Showable{  
public void print( ){System.out.println(“printing….");}  
public static void main(String args[ ]){  
TestInterface2 obj = new TestInterface2();  
obj.print();  
 }  
}  
Output : printing….
As you can see in the above example, Printable and Showable interface have same methods but its implementation is provided by class TestInterface2, so there is no ambiguity.
A class implements an interface, but one interface extends another interface.
interface Printable{  
void print( );  
}  
interface Showable extends Printable{  
void show();  
}  
class TestInterface3 implements Showable{  
public void print( ){System.out.println(“printing…");}  
public void show(){System.out.println(“showing…");}  
  
public static void main(String args [ ]){  
TestInterface3 obj = new TestInterface3();  
obj.print();  
obj.show();  
 }  
}  
printing…
showing…
Since all the fields of an interface are static by default, you can access them using the name of the interface as −
Example

Interface I1{  public static int num = 100; public void display(); }
public class InEx implements I1{
 public static int num = 10000;
public void display() { System.out.println(“In display method");  }
public void show() { System.out.println(“In show method");    }

 public static void main(String args[])
{   InEx obj = new InEx();
      System.out.println("Value of num of the interface "+I1.num);  
    System.out.println("Value of num of the class "+obj.num);    }
}
output:-
Value of num of the interface 100
Value of num of the class 10000

since the variables of an interface are final you cannot reassign values to them.
If you try to do so, a compile-time error will be generated.
A class can implement more than one interface.
A class that implements interface must implements all the methods in interface.
all the fields of an interface are static by default, so you can access them using the name of the interface as
Assignment
Write a program to create an interface Vehicles, and put functionality like changGear, applyBrake,speedUp. And lets Bicycle, Bike, Car classes implement all these functionalities in their own class in their own way.

list of suggested reading
https://www.tutorialspoint.com/how-to-access-the-fields-of-an-interface-in-java
Java: The Complete Reference Book by Herbert Schildt
https://www.youtube.com/watch?v=WZub7Oc3HDo&list=PLA3taA2THXpy0q0TxYd4i5dpk76HpsZ_n

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «java 31 | Extending Interfaces | Accessing interface fields», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.