Static method we can access using Class name and new instantiated variable name(new object). So my question is why don't we declare all methods as static?
Class ShoppingItem{
public static void addItem(Item item){
}
}
Class TestShoppingItem{
ShoppingItem.addItem(Item item);
ShoppingItem sItem = new ShoppingItem();
sItem.addItem(Item item);
}
Aucun commentaire:
Enregistrer un commentaire