+ 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

10th Aug 2018, 7:18 PM
De Vinci
4 odpowiedzi
+ 8
Asker Solution : It is not overridden 💓 🙆‍♂️🤗 function main() calls function c2.where()
1st Sep 2018, 1:51 AM
NimWing Yuan
NimWing Yuan - avatar
+ 1
i didn't get it..can you explain more ?
10th Aug 2018, 10:20 PM
De Vinci
0
because it's being called from within the class iirc
10th Aug 2018, 8:34 PM
hinanawi
hinanawi - avatar
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
11th Aug 2018, 7:01 AM
hinanawi
hinanawi - avatar