0% found this document useful (0 votes)
2 views5 pages

Class Running Notes 14th Oct

The document discusses the introduction of concrete methods in Java interfaces starting from Java 8, including static and default methods, and the addition of private methods in Java 9. It outlines the characteristics and accessibility rules for these methods, emphasizing that static methods are not accessible in implementation classes while default methods are. The document also provides example code to illustrate these concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Class Running Notes 14th Oct

The document discusses the introduction of concrete methods in Java interfaces starting from Java 8, including static and default methods, and the addition of private methods in Java 9. It outlines the characteristics and accessibility rules for these methods, emphasizing that static methods are not accessible in implementation classes while default methods are. The document also provides example code to illustrate these concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Dt : 14/10/2022

Concrete methods in Interfaces:(Java8 - new feature)

=>From Java8 version onwards the interfaces can be declared with

Concrete methods.

=>The following are list of Concrete methods can be declared in

Interfaces:

i
thi
(a)static concrete methods(Java8)

(b)default concrete methods(Java8)

ipa
(c)private concrete methods(Java9)

Ma
(a)static concrete methods(Java8):

=>The concrete methods which are declared in interfaces with "static"

keyword are known as Static concrete methods.


sh
=>These static concrete methods will get the memory within the interface

while interface loading and can be accessed with interface name.


ate

Coding Rule:
nk

=>Static concrete methods of Interface are not available to

implementation classes,which means Implementation classes cannot access


Ve

static concrete methods of Interface.

---------------------------------------------

(b)default concrete methods(Java8):

=>The concrete methods which are declared in Interfaces with "default"

keyword are known as default concrete methods.


=>These "default" concrete methods are only NonStatic methods.

Coding Rule:

=>These "default" concrete methods are available to implementation

classes and which can be accessed with implementation_class

object_reference.

i
thi
---------------------------------------------------

(c)private concrete methods(Java9):

ipa
=>The concrete methods which are declared in interfaces using "private"

keyword are known as private concrete methods.


Ma
=>These private concrete methods are introduced by Java9 version.

=>These private concrete methods are categorized into two types:

(i)static private concrete methods


sh
(ii)NonStatic private concrete methods
ate

Coding Rule:

=>private concrete methods are accessed only inside the interface,


nk

which means private concrete methods are accessed by the NonPrivate

methods of same interface.


Ve

----------------------------------------------------------------

Diagram:
i
thi
ipa
Ex:

ITest.javaMa
package test;
public interface ITest {
public abstract void m1(int x);
public static void m2(int y) {
System.out.println("====static concrete m2(y)====");
sh
System.out.println("The value y:"+y);
}
default void m3(int z,int p,int q) {
ate

System.out.println("====default concrete m3(z)====");


System.out.println("The value z:"+z);
ITest.show1(p);
this.show2(q);
nk

}
private static void show1(int p) {
System.out.println("====private static show1(p)====");
System.out.println("The value p:"+p);
Ve

}
private void show2(int q) {
System.out.println("====private Non-static show2(q)====");
System.out.println("The value q:"+q);
}
}

IClass.java
package test;
public class IClass implements ITest{
public void m1(int x) {
System.out.println("====method m1(x)====");
System.out.println("The value x:"+x);
}
}

DemoInterface4.java(MainClass)

package maccess;

i
thi
import test.*;
public class DemoInterface4 {
public static void main(String[] args) {
IClass ob = new IClass();

ipa
ob.m1(121);
ITest.m2(122);
//IClass.m2(123);//Error
ob.m3(124,125,126);
Ma
}
}

o/p:
sh
====method m1(x)====

The value x:121


ate

====static concrete m2(y)====

The value y:122


nk

====default concrete m3(z)====

The value z:124


Ve

====private static show1(p)====

The value p:125

====private Non-static show2(q)====

The value q:126

=========================================================
Comparision Diagram:

i
thi
ipa
Ma
===========================================================
sh
ate
nk
Ve

You might also like