Java Review _4 interface polymorphism and internal classes

Source: Internet
Author: User

Abstract cannot modify a member variable A class can be defined as an abstract class without an abstract method, so that the object cannot be created by other classes and given to subclasses. Abstract and static (can be called by the class name, but abstract method calls have no meaning)final (cannot be overridden method) private (private method cannot overwrite)Interfaces can only be implemented. The variables defined in the interface to be inherited or used with classes or abstract classes are all constants. The key modifier is public static final. There is no construction method in the interface, and the class construction method of implementing the interface accesses the object, The method in the interface is public,so implementation needs to be aware that it must be publicInterfaces can have no methods that need to be implemented. Interfaces and classes are implementation relationships, and interfaces are inheritance relationships.can inherit more.Abstract class: Inherited is a relationship of is a. The function   interface that defines commonality is the like a relationship, which defines the extension function  javac-d<my_dir> myprogram.java: is to put the   .class  file generated in the Myprogram.java program in the  my_dir  directory, the package used to generate the class file. Can be javac-d. Myprogram.java. (The package that generates the class file under the current path) Imports Import *, represents the wildcard character, it will match under the package, and then import. Access rights:            This category               sub-classes within the same package and unrelated classes     sub-categories under different packages       Different packages of unrelated classes private     &NBS P Y                        N                          N               Ndefault      y                        Y       and nbsp                            NPROTECTE     D    y           &NBSP            Y                       &N bsp;  y               npublic       Y         & nbsp              Y                     &N Bsp    Y               y Inner class:Outer.Inner oi=new Outer (). New Inner ();Inner classes can access private members of external classes directly.static inner class:Outer.Inner oi=new Outer.Inner ();Local inner class accesses local variables local variables must be final decorated. Because when this method is called, if the local variable is not modified by final, the life cycle of the method should be the same as the life cycle of the methods, and the local variables will disappear when the method is stacked. At this point, if the local inner class is not recycled, and want to use this method, it will create a problem.Anonymous inner classes are used only when overriding a single method. When the inner class is a member, it must be added to the main function when you override the Equals method, note that the argument is an object, otherwise it is not overridden but overloaded.the difference between equals and = =: equal can only be compared to reference data types, but the = = number can be compared between reference data type and base data type, and equals is dependent on = =, generally need to rewrite the Equals method.Scanner Hasnextint () determines whether the next number is an integer, judging after calling Nextint (): Gets the input integer,. The standard format is as follows: if (I.hasnextint ()) {int x=i.nextint ();}  When Nextint () and nextline () are combined, nextint () is in the front, and Nextint () takes an integer, no more carriage returns are obtained, so it is obtained by nextline () that the line is closed, so no additional content is output. Solution 1: Create two Scanner Objects 2. Both use the Nextline () method, and then convert to an integer.

Java Review _4 interface polymorphism and internal classes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.