+ 4
Static method cannot be overridden..but why here is overridden ?
class C1 { static void where (){ System.out.println ("you are in c1"); } } class c2 extends C1 { static void where (){ System.out.println ("you are in c2"); } public static void main (String [] args ) { where(); } } //output : you are in c2
4 odpowiedzi
+ 8
Asker Solution : It is not overridden 💓 🙆♂️🤗
function main() calls function c2.where()
+ 1
i didn't get it..can you explain more ?
0
because it's being called from within the class iirc
0
The Green you're not instantiating anything, just calling it from within its' own class so of course it's gonna print the output of it's own method. if you put main in a separate class, and then instantiate an object and call the method (depending on how you do it, not too familiar with java) you'll get a different output