Static methods accessed through the name of the class and instance methods through instance access, why can't static methods and instance methods have the same signature?
The class Test { Public void (A) { } Public static void (A) { } } CodePudding user response:
Because the static methods that can call a static method,
So will appear this kind of circumstance:
static void Main (string [] args) { The Test t=new Test (); T.A (); Console.ReadKey(); } Public class Test { Public void (A) { T1 (); T2 (); } Public void T1 () { Console. WriteLine (" T1 "); } Public static void T2 () { Console. WriteLine (" static T2 "); } } A method called the non-static T1 and T2 of static method,
But what if the static and the static are called T1, it is out of question,
The compiler must don't know what do you want to call which T1,
CodePudding user response:
reference 1st floor is nu month god reply: for the static methods that can call a static method, So will appear this kind of circumstance: static void Main (string [] args) { The Test t=new Test (); T.A (); Console.ReadKey(); } Public class Test { Public void (A) { T1 (); T2 (); } Public void T1 () { Console. WriteLine (" T1 "); } Public static void T2 () { Console. WriteLine (" static T2 "); } } A method called the non-static T1 and T2 of static method, But what if the static and the static are called T1, it is out of question, The compiler must don't know what do you want to call which T1, Truth is the truth, but this can use the this keyword said instance references, with the class watches a static call, bad sort of feeling, CodePudding user response:
reference 1st floor is nu month god reply: for the static methods that can call a static method, So will appear this kind of circumstance: static void Main (string [] args) { The Test t=new Test (); T.A (); Console.ReadKey(); } Public class Test { Public void (A) { T1 (); T2 (); } Public void T1 () { Console. WriteLine (" T1 "); } Public static void T2 () { Console. WriteLine (" static T2 "); } } A method called the non-static T1 and T2 of static method, But what if the static and the static are called T1, it is out of question, The compiler must don't know what do you want to call which T1, public class Test { Public void (A) { This. (T); Test. T (); } Public void (T) { Console. WriteLine (" T "); } Public static void (T) { Console. WriteLine (" Static T "); } } Why can I feel like this? Maybe I was a bar fine CodePudding user response:
reference yunlovejia reply: 3/f Quote: refer to 1st floor is nu month god reply: Because the static methods that can call a static method, So will appear this kind of circumstance: static void Main (string [] args) { The Test t=new Test (); T.A (); Console.ReadKey(); } Public class Test { Public void (A) { T1 (); T2 (); } Public void T1 () { Console. WriteLine (" T1 "); } Public static void T2 () { Console. WriteLine (" static T2 "); } } A method called the non-static T1 and T2 of static method, But what if the static and the static are called T1, it is out of question, The compiler must don't know what do you want to call which T1, public class Test { Public void (A) { This. (T); Test. T (); } Public void (T) { Console. WriteLine (" T "); } Public static void (T) { Console. WriteLine (" Static T "); } } Why can I feel like this? Maybe I was a bar fine May be more or design of the Java and.net, considering the factors, It's like why abandoned the multiple inheritance, adopting the single inheritance, Must say why, said that in order to simplify the class, do not let him become complex, it is a bit pale, But in fact, this was what,