Java puzzle Seven: Many other categories of mysteries

Source: Internet
Author: User
Tags instance method uppercase letter

Puzzle
the issue of inheritance.
For instance methods: When naming the same, subclasses overwrite the methods of the parent class, and the access permission is at least as large as the parent class.
for domain: Naming the same, subclasses hide the domain of the parent class and are free to access.
Puzzle
do not reuse the class names in the library.
Puzzle
named question.
The
class name should start with an uppercase letter in the form: Mixedcase.
The
variable starts with a lowercase letter in the form: Mixedcase.
constants begin with an uppercase letter in the form: Mixed_case.
a single capital letter that can only be used for type parameters in the form: Map<k, v>.
The
package name should all be lowercase, in the form: Lower.case.
when a variable and a type have the same name and are used for the same scope, the variable name has precedence.
That is: variable name masking (obscure) type name. The same variable name and type name can obscure the package name.
Class X {static class Y {static String Z = "Black";} Static C Y = new C ();} Class C {String Z = "White";} public class Shadesofgray {public static void main (string[] args) {System.out.println (x.y.z);//output is: white}}
Puzzle
How to refer to the masked type name in the above topic. The technique uses the name in a particular grammatical context, and the syntax context agrees to appear with a type name but does not agree to the occurrence of the variable. Skill One
<span style= "FONT-SIZE:18PX;" >system.out.println (((x.y) null). Z);</span>
Tip Two
<span style= "FONT-SIZE:18PX;" >static class Xy extends x.y{}; System.out.println (xy.z);</span>
tip Three: After the 5.0 version number
<span style= "FONT-SIZE:18PX;" >public static <t extends x.y> void Main (string[] args) {       System.out.println (t.z);} </span>
Puzzle
A class with a method that has access to the package, which cannot be overwritten when it is inherited within another package.
Even the method name is two different methods.
Puzzle
name reuse leads to shadowing (shade): A declaration can only obscure the type as well as a declaration. Static import of arrays.tostring, when using ToString () in a class, calls the ToString method in the object class.
Puzzle
the problem of name reuse.
final modifier
for methods: instance methods cannot overwrite, static methods cannot be hidden.
for Domains: cannot be assigned more than once. So it can be hidden.
Puzzle
Masking: A masked type can come from a perimeter class, not from a library.
Hide: The variable that originally called the parent class, the result declares a private variable with the same name.
Puzzle
The overloaded method determines that all overloaded version numbers are identical.
Puzzle
version number after the upgrade to bring inconsistencies, understand it.
Name Reuse Glossary
Overwrite (override) An instance method is able to overwrite (override) The full instance method that has the same signature in its superclass, so that it can be dynamically dispatched, and the VM chooses the override method to invoke based on the instance execution period type.
Class Base {public     void F () {}}class Derived extends Base {public    void F () {}//override base.f ()}
overloading (overload) in the same class, the method name is the same, and the signature is different. The overloaded method is the compile-time selected
Class A {public     void F (int. i) {} public     void F (String s)  {}}
Hidden (hide) a field in a subclass, a static method, or a member type can hide all and static methods or member types in a superclass that have the same name. hiding a member will prevent it from being inherited.
Class Base {public     static void F () {}}class Derived extends Base {public     static void F () {}}
Masking (Shadow) A variable, method, or type can mask all variables, methods, or types that have the same name in the text range.
Class Whoknows {      static stirng sentence = "I do not know";        public static void Main (string [] args) {              string sentence = "I know";//shadow static field               System.out.println (sen tence);}         }
masking (obscure) variables can obscure the same name type within the same range, a variable or type can hide a package.
public class Obscure {    static String System,//obscures type Java.lang.System public    static void Main (string[] Arg s) {     System.out.println ("Hello");//won ' t compile    }}

Java puzzle Seven: Many other categories of mysteries

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.