I spent the afternoon Corejava to consolidate the basic concepts and deepen our understanding. It's not good to draw a pen on it. Tomorrow try to record the problems or some unfamiliar terminology or concepts, and then use the special time to solve the problems of reading. When reading a book, the Testdemo is not saved. , with a rewrite and overloaded code along with some notes.
Method overrides, method overloading overloading concepts:
Method overrides (Overrides) refer to the same method name and argument list in the subclass when the method inherits, but with different methods, regardless of the return value
Method overrides allow subclasses to override the same method in the parent class, which requires access permission to be less than the parent class, and the method modifier to be consistent with the parent class
Method overloading refers to methods in this class where multiple methods have the same name but different parameter lists, regardless of the return value.
Method overloading is the implementation of similar methods for different parameter types or the number of response processing
/** method overload overloading: Refers to methods in this class that have multiple methods with the same name but different parameter types/numbers. * The return type cannot be used as a distinguishing criterion for overloaded functions. * Overloaded overloading is a representation of polymorphism in a class. * When calling methods, it is polymorphism to decide which method to use by passing them the number of different arguments and the type of parameter. */ Public classOverloading {intAddinta) {returnA; } intAddintAintb) {returnA +b; } //void Add (int a,int b) {//cannot define method overloads based on return value type// // }}
/** Method Override overriding: Polymorphism between parent class and child class*/classFu { Public voidShow () {System.out.println ("Parent class Show Method"); }}classZiextendsFu { PublicString Show (inta) {String s= "(String) show (int a) method in subclass"; returns; } Public voidShowintAintb) {System.out.println ("Method overloads in subclasses"); } Public voidShow () {System.out.println ("Subclass method overrides for parent class"); }} Public classoverriding { Public Static voidMain (string[] args) {Fu F1=NewFu (); F1.show (); Fu F2=Newzi (); //f2.show (1);//compile look left, no method of show (int a) in parent classF2.show ();//()Zi z =Newzi (); Z.show (The); System.out.println (Z.show (12)); }}
Thursday, January 15