Introduction
A user-defined package is created with the help of the “package” keyword. Whereas to use a package we use the import keyword.
Demo.java
- package abhi;
- public class Demo {
- public void sum(int num1, int num2) {
- int result;
- result = num1 + num2;
- System.out.println("the sum of two numbers is:" + result);
- }
- }
Tester.java
- import abhi.Demo;
- class Tester extends Demo {
- public static void main(String args[]) {
- Tester obj = new Tester();
- obj.sum(10, 20);
- }
- }
Procedure to run the program:



Join the conversation! Your thoughts help the community grow.