public class MyClass { public int publicVar; protected int protectedVar; int defaultVar; // Default access (no modifier) private int privateVar; public void publicMethod() { // Public method accessible from anywhere } protected void protectedMethod() { // Protected method accessible within the same package or by subclasses } void defaultMethod() { // Default method accessible only within the same package } private void privateMethod() { // Private method accessible only within the same class } }