public
protected
default (no modifier)
private
public:
protected:
default (no modifier):
private:
| Access Modifier | Same Class | Same Package | Subclass (Other Package) | Other Package |
|---|---|---|---|---|
| public | β | β | β | β |
| protected | β | β | β | β |
| default | β | β | β | β |
| private | β | β | β | β |
public class Car
{
private String model;
protected int speed;
public void startEngine()
{
System.out.println("Engine started");
}
}
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
Weβre here to make our tutorials better based on your thoughts and suggestions.