Problems about construction methods

xiaoxiao2021-03-06  69

what does this mean? The function of the default constructor is to call the constructor of the non-parameter of such parent class. Class Rock {Rock (INT i) {system.out.println ("no" i);}} Class Subrock Extends Rock {public static void main (string args []) {for (int i = 0; I <10; i ) {new Rock (i);}}} The seventh line has problems, saying is that the parent class does not have a constructor! Rock (INT I) {} is not a construction method?

Question Solution: I have an understanding error here. Not Rock (INT i) {} is not a constructor, but because the construction method with parameters is established, it covers the system default constructor. The original words in the reference book is "The function of the default constructor is to call the constructor of the non-parameters in such parent classes. If there is no such constructor in the parent class, it will errors when compiling." Class Rock {Rock (INT i) {system.out.println ("no" i);}} / * class subrock extends Rock {} * / public class simpleconstructor {public static void main (string args []) {for INT i = 0; i <10; i ) {new Rock (i);}}} According to the above concept, the part is annotated, compiling

转载请注明原文地址:https://www.9cbs.com/read-120459.html

New Post(0)