Java Interface-10 Programs

interface {// declare constant fields// declare methods that abstract// by default.}
Somnath10
drawing circle
ROI: 9.15

Multiple inheritance in Java by interface

If a class implements multiple interfaces, or an interface extends multiple interfaces, it is known as multiple inheritance.

PROGRAM 5: Multiple inheritance in Java by interface example.

Here I have created two interface and on class .so nnow I can use both interface property.

Output:HelloWelcome

PROGRAM 6: Multiple inheritance in Java by interface example no two.

CODE:

HelloWelcome

Java 8 Default Method in Interface

Since Java 8, we can have method body in interface. But we need to make it default method. Let’s see an example:

drawing rectangledefault method

Java 8 Static Method in Interface

Since Java 8, we can have static method in interface. Let’s see an example:

Program 8: Java 8 Static Method in Interface

example

drawing rectangle27

Java Nested Interface

An interface, i.e., declared within another interface or class, is known as a nested interface. The nested interfaces are used to group related interfaces so that they can be easy to maintain. The nested interface must be referred to by the outer interface or class. It can’t be accessed directly.

Syntax of nested interface which is declared within the interface

interface interface_name{

Syntax of nested interface which is declared within the class

class class_name{

Example of nested interface which is declared within the interface

In this example, we will learn how to declare the nested interface and how we can access it

PROGRAM 9: nested interface which is declared within the interface

Here I have used two inteface showable and inside its Message
hello nested interface

Example of nested interface which is declared within the class

Let’s see how we can define an interface inside the class and how we can access it.

PROGRAM 10: Example of nested interface which is declared within the class

CODE:
}OUTPUT:
Bicycle present state :speed: 2 gear: 2Bike present state :speed: 1 gear: 1

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store