Technotaught

Addition and multiplication Program using the user-defined package

In this article, we see Addition and multiplication Program using the user-defined package

Java package is a mechanism of grouping similar types of classes, interfaces, and sub-classes collectively based on functionality. When software is written in the Java programming language, it can be composed of hundreds or even thousands of individual classes. It makes sense to keep things organized by placing related classes and interfaces into packages.

Program to create a user-defined package

Addition and multiplication Program using user-defined

Source code
//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 

Also, you can use the Java compiler to compile a program.

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

Also, View: – Write a program to create a registration form using AWT.

Also, View- Write a java program to create a window using swing.

Exit mobile version