Syntax error Difference Between Packages and Interfaces in Java

Difference Between Packages and Interfaces in Java



In this post, we will understand the difference between packages and interfaces in Java.

Packages

  • It is a group of classes and/or interfaces that are together.

  • It can be created using the "Package" keyword.

  • It can be imported.

  • It can be done using the "import" keyword.

Example

package package_name;
public class class_name {
   .
   (body of class)
   .
}

Interfaces

  • It is a group of abstract methods and constants.

  • It can be created using the "Interface" keyword.

  • It can be extended by another interface.

  • It can also be implemented by a class.

  • It can be implemented using the ‘implement’ keyword.

Example

interface interface_name {
   variable declaration;
   method declaration;
}
Updated on: 2021-03-24T13:06:17+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements