Static - Day 4 Flashcards
Static variable
Static variable belongs to an entire class not a specific object
What is happening with static variables?
Variable is created and shared among all objects at the class level.
Member variable
Variables consisting to the class so instance and static variables
Set up
private static datype varname;
Static methods
Can only access static variables.
Can be engoles without creating an instance of a class, setter and getter methods:
Public static float getDeliverycharge() {
Return deliveryCharge;
}
Public static void setDeliveryCharge(float deliveryCharge) {
Customer.deliveryCharge = deliveryCharge;
}
Statics work only with statics
Can’t call instance members directly!!