Close Menu
Durofy – Business, Technology, Entertainment and Lifestyle Magazine
  • Business
  • Technology
  • Engineering
  • Startups
  • Coding
  • Entertainment
  • Lifestyle
  • Real Estate
  • Finance
  • Tools
  • Coupon
Facebook X (Twitter) Instagram Pinterest
Trending
  • How a Portable Dishwasher Changed My Small Kitchen
  • Why Nautica Voyage Stuck With Me
  • Comfortable Black Dress Oxfords That Actually Work
  • The Hospital Paperwork That Can Shape Your Injury Case
  • The $20 Cardigan That Fixed My Fall Wardrobe
  • How One $4 Brow Pencil Fixed My Sparse Brows
  • Your Devices Testify Before You Do: What Smart Home and Wearable Data Reveal After a Car Crash
  • The Renewal Offer Got Weird: Four Lease Deal Formats Landlords Are Sending in 2026
Facebook X (Twitter) Instagram
Durofy – Business, Technology, Entertainment and Lifestyle MagazineDurofy – Business, Technology, Entertainment and Lifestyle Magazine
Subscribe
Thursday, September 10
  • Business
  • Technology
  • Engineering
  • Startups
  • Coding
  • Entertainment
  • Lifestyle
  • Real Estate
  • Finance
  • Tools
  • Coupon
Durofy – Business, Technology, Entertainment and Lifestyle Magazine

Interface in JAVA

Guest AuthorsBy Guest AuthorsFebruary 2, 2013Updated:March 21, 2016 Coding No Comments4 Mins Read

  Interface in java

1. An interface is a type used for accessing the members of some other class instance.

2. Group of abstract methods is called ‘interface’

  •      There is no members confliction in interface because the members functions/methods have only   prototype, that’s why use application of multiple inheritance through interface.
  •     The member that an interface intended to access are declared as it’s abstract method.

syntax for declaration of interface in java :

   interface interface_name

                {

                     // static final variables

                    // abstract and public abstract methods

                }

5.  A class implements an interface using “implements” keyword.

6. When a class implements an interface using it must implement all of its abstract methods otherwise class must abstract.

7. One class may implement multiple interfaces so that instance gets multiple references.

8. One interface may inherit one or one more interface using “extends” keyword.

9. An interface may contain only abstract methods but in addition static final properties ans static inner classes.

10.The Methods in interface are by default abstract, the properties are by default static final , the inner classes are static ans all members are always public.

Lets see the example which satisfies all the above points we have mentioned.

interface A

{

    int sum();       // point 3

}

interface B

{

    int difference();       // point 3

}

interface C extends A,B         // we can it as multiple inheritance ( point 8)

{

   int product();

}

interface D

{

int division();     // point 9

}

class calculate implements C,D         //point 5

{

int fno,sno;

public calculate(int fno,int sno)

{

this fno=fno;

  this.sno=sno;

}

public int sum()

{

  return fno+sno;

}

public int difference()

{

   return fno-sno;

}

public int division()

{

   return fno/sno;

}

public int product()

{

 return fno*sno;

}

} // class calculate close

public class Main()

{

public static void main(String[] args)

{

 Calculate cal=new Calculate(20,10);     // point 7

 A a - cal;                                            //point 1

 B b = cal;

 C c = cal;

 D d = cal;

 int result= a.sum();

 System.out.println(" The sum of two numbers is :"+ result);

 int result= b.difference();

 System.out.println(" The difference of two numbers is :"+ result);

 int result= c.sum();

 System.out.println(" The product of two numbers is :"+ result);

 int result= d.sum();

 System.out.println(" The division of two numbers is :"+ result);

}// main close

} // class close

 

 

OUTPUT :

The sum of two numbers is : 30

The difference two numbers is : 10

The product of two numbers is : 30

The division of two numbers is : 30

 

Finally Save, Compile, Run and Observe the Output.

Note :

  • None of the methods in an interface should be private, protected and static.
  • At compile time , all interface are converted into bytecode( .class) . i.e., in the above example will get A.class, B.class, C.class and D.class apart from “Calculate.class”.

 

Point to Ponder:
1. While designing, how do you choose between Abstract & Interface ?

Answer : Use an abstract class when a template needs to be defined for a group of subclasses
Use interface when role needs to be defined for other classes irrespective of the inheritance tree of the classes

2. Can an interface be instantiated in Java?

Answer : No, an interface can not be instantiated in Java.

 3. Why the methods of interface are public and abstract by default ?

Answer: Interface methods are public since they should be available to third-party vendors to provide implementation. They are abstract as the implementation is left to third party.

4. Can we write a class with in an interface ?

Answer : Yes we can write a class with an interface .

For further discussion, leave a comment below.

Previous Article[C# Tutorial 6] Statements
Next Article How an Aircraft Flies – An Introduction to Aircraft Lift and Thrust

Keep Reading

Discovering CodeMonkey: A Family Coding Adventure

How I Finally Broke Through My Coding Plateau with Educative.io

The Future of Work: How AI and Large Language Models Are Reshaping Jobs

5 Web Design Mistakes You’re Making (That Are Turning Off Customers)

Educative.io: The Best Interactive Courses for Developers & Programmers in 2024

CodeMonkey: The Best Platform for Game-Based Programming for Kids

Add A Comment
Leave A Reply Cancel Reply

💰 Hiring Work From Home Job

Complete Online Surveys & Data collection

Flexible part-time work from anywhere. Get paid via PayPal or gift cards for sharing your opinions. No experience needed!

Start Earning Now →

Legitimate opportunities • Work on your own schedule

Recent Posts
  • How a Portable Dishwasher Changed My Small Kitchen
  • Why Nautica Voyage Stuck With Me
  • Comfortable Black Dress Oxfords That Actually Work
  • The Hospital Paperwork That Can Shape Your Injury Case
  • The $20 Cardigan That Fixed My Fall Wardrobe
  • How One $4 Brow Pencil Fixed My Sparse Brows
  • Your Devices Testify Before You Do: What Smart Home and Wearable Data Reveal After a Car Crash
  • The Renewal Offer Got Weird: Four Lease Deal Formats Landlords Are Sending in 2026
  • How One Cream Changed My Morning Routine
  • From Stiff Dress Pants to All-Day Comfort: My Switch to Libin Golf Pants
  • How COSRX Snail Mucin Fixed My Skin Barrier
  • These Soft Cork Footbed Clogs Actually Deliver All-Day Comfort
  • How This Cookware Set Changed My Kitchen Routine
  • How a Simple Green Tree of Life Tapestry Transformed My Space
  • The Boots That Actually Delivered

ABOUT DUROFY

Durofy is a business, technology, science, lifestyle and entertainment digital media platform and news website founded in 2009.

Contact Durofy

For business or advertising, contact us at durofy@live.com.

Social

Like us on Facebook

Facebook X (Twitter) Instagram Pinterest
© 2026 ThemeSphere. Designed by ThemeSphere.

Type above and press Enter to search. Press Esc to cancel.