0
Can i call a method defined in a class without creating an object of that class?
4 Answers
+ 2
yes you can, just make it static and call it with a period/dot (.)
+ 2
Make the method static.
0
public class dog{
static void bark(){System.out.println("woof");}/*you have created a block and assigned bark with "woof"*/
main
/*calling bark from dog*/dog.bark();
}
/*output "woof"*/
/*im learning my self so im assuming this is correct as this is how i see it*/
0
in this case if I only write
bark(); instead of dog.bark();
then too output will be same