8)Write a program to utilize both standard and custom packages. The program should reflect the usage of packages in a correct manner, along with the purpose of access modifiers

PHOTO EMBED

Mon Jul 08 2024 06:05:03 GMT+0000 (Coordinated Universal Time)

Saved by @varuntej #java

package com.example.custom;
import java.util.ArrayList; // Import ArrayList from java.util package
class CustomClass {
void display() {
System.out.println("Custom class in the custom package.");
}
}
public class Main {
public static void main(String args[]) {
ArrayList list = new ArrayList<>(); // Fix the typo in ArrayList declaration
list.add("hello");
list.add("world");
System.out.println("ArrayList from java.util package: " + list);
CustomClass customObj = new CustomClass();
customObj.display();
AccessModifiersDemo demo = new AccessModifiersDemo();
demo.publicMethod();
demo.defaultMethod();
}
}
class AccessModifiersDemo {
public void publicMethod() {
System.out.println("Public method can be accessed from anywhere.");
}
void defaultMethod() {
System.out.println("Default method can be accessed within the same package.");
}
}
content_copyCOPY