I'm a beginner in java and I have a Drink class where I have a method showAll() to print all my drink objects that are stored in a private hashset . In my main function I can have access to this method by saying
Drink test = new Drink(value1 , value2 , ....);
test.showAll();
Is there a way to access my showAll() method without creating an object as I just want to print all the array objects without the need to create a new object each time I want to print
Drink.java
private static HashSet<Drink> drinks = new HashSet(); //store all drinks in hashset
public void AddDrink(Drink d ){ //add a drink
try {
drinks.add(d);
}catch(Exception e ){
System.out.println(e);
}
}
public void showAll() { //show all drinks
for(Drink d : drinks) {
System.out.println(d);
}
}