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
  1. package abhi;
  2. public class Demo {
  3. public void sum(int num1, int num2) {
  4. int result;
  5. result = num1 + num2;
  6. System.out.println("the sum of two numbers is:" + result);
  7. }
  8. }
Tester.java
  1. import abhi.Demo;
  2. class Tester extends Demo {
  3. public static void main(String args[]) {
  4. Tester obj = new Tester();
  5. obj.sum(10, 20);
  6. }
  7. }
Procedure to run the program:
First compile the Demo.java as follows:
For compilation Demo.java:
javac –d . Demo.java
Secondly, compile the Tester.java in another Command Prompt.
For compilation Tester.java:
javac Tester.java
java Tester
Output
Image-1.jpg
Image-2.jpg