Instructions
1. Define the in variable and use the upper limit wildcard character.
Use the extends keyword.
2. Use the super keyword and the lower limit wildcard to define the out variable.
3. If the In variable can be accessed using the method defined in the Object class, use unbounded wildcards.
4. When the code needs to access In and out variables, do not use wildcards.
Example
// 自然数 class NaturalNumber { private int i; public NaturalNumber(int i) { this.i = i; } // ... } // 偶数 class EvenNumber extends NaturalNumber { public EvenNumber(int i) { super(i); } // ... }
Java is an object-oriented programming language that can write desktop applications, Web applications, distributed systems and embedded system applications.
The above is the detailed content of What are the rules for using wildcards in java. For more information, please follow other related articles on the PHP Chinese website!