Preview:
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.");
}
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter