Explain the extends and super keywords inherited by Java, extendssuper
A function is also called a method!
Inheritance: Use the extends keyword in java to represent the inheritance relationship. Super is used to inherit the methods and parameters of the parent class.
Inherit
Simply put:1.extends is inherited from the parent class, as long as the class is not declared final or the class is defined as abstract to inherit,Multiple inheritance is not supported in 2.JAVA, but can be implemented with interfaces, which will use the implements,3. Inheri
I am confused by the Java language, the extends and implements in the Code. Now I can understand the differences and usage between them.
// Define a runner interface
// Define an interface animal that inherits from the parent class runner
// Defines the fish class, which implements the methods run () and breather ()
from the subclass, regardless of how the subclass is scheduled to eventually be called, the default call to the parent class without a parameter in the constructor method
3
Requirements
Place the first row of the constructor method when invoking its own construction method
The first row of the child class construction method is placed when the parent
same2. Subclass throws an exception that cannot exceed the exception thrown by the corresponding method of the parent class3. The access level of the subclass method must not be lower than the access level of the corresponding method of the parent class (such as the parent class method, protected, subclass rewrite will be protected or public)Such as:
public
Java basics-super and this parsing, extends uper
1. The super keyword indicates the meaning of the super (parent) class. This variable represents the object itself.
2. super accesses hidden variables or override methods of the parent quilt class. If the current class is inhe
Mystring {
public static void Main (string[] args) {
Student ok=new Student ("Xiaoming");
Ok.say (); The//say method has been inherited.
}
}
Class Person
{
public String name;
public void Say ()
{
System.out.println ("The name is:" +name);
}
}
Class student e
file output below System.out.println (" Aaaaaaaaaaaaaaaaaaa "); System.out.println ("i=" +i);//Assign the input I to the member variable Numnum=i;}} b Inherits AClass B extends A{int num=0;//member method B.public B () {//Inherits the method of Class A. Since B inherits a, it inevitably inherits the characteristics of a. So the input int value 10 is implemented by the method. Super (10); System.out.println
In the observation of Java source code, the discovery of such a notation T extends comparableNext, I'll share the code with you about my view of generics here.1. ?
As you can see, this applies to generics in Java, so let's start by explaining the role of extends here.
Generics are added in Java 1.5, and the details of generics are not discussed here, which is very clear in the fourth edition of Thinking in Java, which is about the super and extends keywords, and why there are different limitations when using these two keywords.First, we define two classes, A and B, and assume that b inherits from a. Packagecom.wms.test;Importj
Understanding inheritance is the key to understanding object-oriented programming. In Java, inheriting an existing class through Keywordextends, the inherited class is called the parent class (superclass, base class), and the new class
Understanding inheritance is the key to understanding object-oriented programming. In Java, an existing class is inherited by the keyword extends, the inherited class is called the parent class (the superclass, the base class), an
upper bound wildcard character (Upper Bounds wildcards)"
Nether wildcard (Lower Bounds wildcards)"
1. Why use wildcard characters and boundaries?In the process of using generics, a very awkward situation often arises. For example, we have the Fruit class, and its derived class, the Apple class, in the case of the main topic.class Fruit {}
method, unless the instance method contains a local variable with the same name as the member variable.Access to member variables requires the use of this.4. When a class contains more than one constructor method, if one of the constructor methods is to invoke another constructor method, use thepublic class this{Public this () {This ("white"); Using this method to construct a parameter in an argument-free
Keyword description
●? Wildcard type
●
● Extends example
Static class food {}Static Class fruit extends food {}Static class Apple extends fruit {}Static class redapple
class is not inherited.But the constructor is another matter.2. Class initialization is performed only once, and when multiple objects are new to the same class, class properties and class initialization blocks are initialized only once.3. Modifiers in inheritance and prope
between them is:1. As we all know, Java is a single inheritance mechanism, and it is not allowed to inherit multiple classes at the same time. Therefore, when you inherit the thread class (extends thread), you can no longer inherit other classes. And you implement the Runnable interface is not the same, you can inherit other classes.2. When you inherit the threa
Differences between super T and extends T in Java generics
The declaration of List
Extends
The wildcard declaration of List
// Number "extends" Number (in this context)
List
// Integer extends Number
List
// Double
This article talks about Java Generic Declaration
? The extends e> is the Upper Bound (upper bound) wildcard that restricts the upper bounds of the type of the element, such as
listIndicates that the upper bound of the element type in the collection is a fruit type, that is, only a subclass of fruit or fruit, so it is reasonable for the following assignment
Fruits = new arraylistIf the parent
As we all know, to implement Java multi-threading Two ways A: is directly inherit the thread class, B: is to implement the Runnable interface.First on the code:A: The thread class is inherited directly,public class ThreadDemo1 extends Thread {public void Run () {Thread.Curre
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.