Topics:
--------------------
What is a Static method?
What are the Static methods in Interfaces?
How to declare a Static Method in Interface?
Why we need a Static Method in Interface?
How to define main() method inside an Interface ?
Can we have main() Method inside an Abstract class & Enum ?
How to call static method of an Interface?
Can we Override Interface’s static methods?
How will you define an Interface after introduction of default & static methods?
FAQ
Can a method be declared Default & Static together in an Interface?
What is the benefit of using static methods in interfaces?
Can interfaces have both static and default methods?
Is it mandatory to provide an implementation for static methods in an implementing class?
=============================================
//Every instance of the class shares its static methods
interface A{
public static void m1(){
System.out.println("static method in interface from java 1.8");
}
}
---------------------------
//static method in interface (valid from java 1.8)
interface A{
public static void main(String[] args){
System.out.println("static main method in interface from java 1.8");
}
}
//static method inside abstract class (valid from java 1.4)
public abstract class B{
public static void main(String[] args){
System.out.println("static main method in abstact class from java 1.4");
}
}
//static method inside enum (valid from java 1.5)
public enum C{
;
public static void main(String[] args){
System.out.println("static main method in enum from java 1.5");
}
}
--------------------------------------
interface A{
public static void m1(){
System.out.println("static method in interface from java 1.8");
}
}
class X implements A{
public static void main(String[] args){
A.m1();
}
-------------------------------------
interface A{
public static void m1(){
System.out.println("static method in interface from java 1.8");
}
}
Class T1 implements A{
public static void m1(){
System.out.println("Not overridden method");
}
}
Class T2 implements A{
public static void m1(){
System.out.println("Not overridden method");
}
}
------------
interface A{
default static void m1(){
System.out.println("Invalid method");
}
}
----------------------
#interview #java8 #javaprogramming #java #javatutorial #javainterview #javainterviewquestions
Auf dieser Seite können Sie das Online-Video Static Methods In Interface || Java 8 Features mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer CodeTav Management 24 Dezember 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 35 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!