Java Program to Create an Interface With a Data Member

You are currently viewing Java Program to Create an Interface With a Data Member

Java program to create an interface with a data member

// Java program to create an interface 
// with a data member

interface Inf {
  int num = 10;

  //public and abstract
  void printNum();
}

public class Main implements Inf {
  public void printNum() {
    System.out.println("Num: " + num);
  }

  public static void main(String[] args) {
    Main mObj = new Main();

    mObj.printNum();
  }
}

Output

Num: 10

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply