Practical No. 20
Practical No. 20
20
Program Code: Write a program to implement user defined packages in terms of
creating a new package and importing the same.
1)
package myPackage;
public class MyClass {
public static void sayHello() {
System.out.println("Hello & Welcome to My Class!");
}}
2)
import myPackage.MyClass;
public class Hello {
public static void main (String [] args) {
MyClass.sayHello();
}}
Exercise:
1. The code uses the class defined below. Class Importclass is not defined in
circle folder. Will the code run without giving any errors?
import circle.NewCircle;
class ImportClass{
System.out.println(“Hello Java”);
}}
Yes, the code should run without any errors as long as NewCircle class is defined correctly in
the circle package and is accessible to the main method of the ImportClass class.
import java.util.*;
staffName = s.nextLine();
staffid = s.nextInt();
dptName = s.nextLine();
return staffName;
return staffid;
return dptName;
}}
2)
import myInstitute.*;
class Main{
obj.display();
System.out.println("Name is :"+ obj.getStaffName());
}}