+ 2
Please Explain the Use of Static in java briefly with a good example.
It would be nice if 2 example programs with and without static is explained in the answer.
3 Antworten
+ 6
class Car {
public void any() {
// do anything
}
}
class Bus {
public static void any() {
// do anything
}
}
Car car = new Car(); // create object first (non-static)
car.any(); // then call method
Bus.any(); // direct call method (static)
+ 2
So that means , if the method is static then there is no need to create an object to call that method ?
+ 1
yes