#15 : Write a program to create a user defined Package.

Source code .

Table of Contents

//CREATE A NEW FILE NAME AS A1
package A1; 
public class A// DEFINE IN PACKAGE A1
{
	public void add(int x,int y)
	{ 
	int z=x+y;
	System.out.println("Addition"+z);
	}
}//END OF CLASS

//CREATE A NEW FILE NAME AS A2
package A2; 
public class B //DEFINE IN PACKAGE A2 
{
	public void mul(int x,int y) 
	{
	int z=x+y;
	System.out.println("Multiplication"+z);
	}
}//END OF CLASS

//CREATE A NEW FILE NAME AS pack
import A1.A; 
import A2.B; 
public class pack 
{
	public static void main(String args[]) 
	{
		A a-new A(); //OBJECT OF CLASS A 
		B b:new(); // OBJECT OF CLASS B 
		a.add(10,20);
		b.mul(10,20)
	}//END OF MAIN 
}//END OF CLASS 

Output.

C: \A>javac -d . A.java
C: \A>javac -d . B.java
C: \A>javac pack.java
C:\A>java pack
Addition=30
Multiplication=200

About Ashishkumar Vishwakarma

I am Ashish- a Developer live in Mumbai.

View all posts by Ashishkumar Vishwakarma →

Leave a Reply

Your email address will not be published. Required fields are marked *