you assign a value 3,a=3, at this point A is an integer reference, but Python is not a weak type language, in Python ' 2 ' +3 will error, and in PHP ' 2 ' +3 will be 5. As you can see, the variables in Python are similar to those in C, unlike C, where variables in Python can point to any type, although that's not very accurate, but easier to understand.As a result, the parameters are not known until the parameter is passed through the Python runtime, although the methods in Python are late-boun
class is loaded, only one storage space is allocated, and all objects of this class can manipulate this block of storage space, of course, for final.class Value {Staticint c = 0;Static Void Inc () {c+ +;}} Publicclass Count2 { PublicStatic void prt (String s) {System. out. Print (s);} PublicStatic void Main (string[] args) {Value v1, v2;V1 = new Value ();V2 = new Value ();PRT ("v1.c=" + v1. c + "v2.c=" + v
loaded, only one storage space is allocated, and all objects of this class can manipulate this block of storage space, of course, for final.Class Value {STATICINTC = 0;Staticvoid Inc () {C + +;}}Publicclass Count2 {Publicstaticvoid prt (String s) {System.out.print (s);}Publicstaticvoid Main (string[] args) {Value v1, v2;V1 = new Value ();v2 = new Value ();PRT ("v1.c=" + v1.c + "v2.c=" + v2.c);V1.inc ();
class is loaded, only one storage space is allocated, and all objects of this class can manipulate this block of storage space, of course, for Final.class Value {Staticint C = 0;Static Void Inc () {C+ +;}} publicclass Count2 { publicStatic void prt (String s) {System. Out. Print (s);} publicStatic void main (string[] Args) {Value v1, v2;V1 = new Value ();V2 = new Value ();PRT ("v1.c=" + v1. C + "v2.c=" + v
First, take a look at a piece of code to test everyone. Please output the following code results without running the program:
class Insect {int i = 9;int j;Insect() {prt("i = " + i + ", j = " + j);j = 39;}static int x1 = prt("static Insect.x1 initialized");static int prt(String s) {System.out.println(s);return 47;}}public class Test extends Insect {int k =
original order (that is, the order in which they are written in the class definition code ).Of course, static data is initialized only once.
6.9.1 inheritance InitializationWe need to understand the entire initialization process, including inheritance, and have a holistic concept of what happens in this process.Observe the following code:
//: Beetle. Java// The full process of initialization.
Class insect {Int I = 9;Int J;Insect (){PRT ("I =" + I + "
Polymorphism
Is a technology that allows you to set a parent object to be equal to one or more of its sub-objects, such as parent: = Child; polymorphism allows you to use the same class (base class) type pointer to reference objects of different classes, and perform the same operation in different ways according to different referenced objects.
The concept of polymorphism in C ++ is easier to understand.
A parent class pointer or name is allowed to reference a subclass object or an o
It is necessary to have an understanding of the entire initialization process, including inheritance, which has a holistic concept of what is happening in the process. Please observe the following code:
: Beetle.java
//The full process of initialization.
Class Insect {
int i = 9;
Int J;
Insect () {
prt ("i =" + i + ", j =" + j);
j = k;
}
static int x1 =
prt ("Static insect.x1
);
}
PublicStaticVoidMain (String[] ARGs ){
Value V1, V2;
V1 =NewValue ();
V2 =NewValue ();
PRT ("v1.c =" + v1.c + "v2.c =" + v2.c );
V1.inc ();
PRT ("v1.c =" + v1.c + "v2.c =" + v2.c );
}
}
The result is as follows:V1.c = 0 v2.c = 0V1.c = 1 v2.c = 1This proves that they share a storage zone. Static variables are similar to global variables in C. It is worth exploring the initialization of stati
code block execution order depends on the order of the encoding. Who executes first in front.
Initialization of non-static Properties
Class Animal {
Animal (int age) {
System.out.println ("Animal (" + Age +) ");
}
void f (int age) {
System.out.println ("f (" + Age +) ");
}
public class Notstaticinit {
Animal A1;
Animal A2;
{
A1 = new Animal (1);
A2 = new Animal (2);
System.out.println ("A1 A2 initialized");
}
Notstaticinit () {
System.out.prin
example below: class person {
Public static void PRT (string s ){
System. Out. println (s );
}
Person (){
PRT ("A person .");
}
Person (string name ){
PRT ("A person name is:" + name );
}
}
Public class Chinese extends person {
Chinese (){
Super (); // call the parent class Constructor (1)
PRT ("A Chinese."); // (4)
}
age = 22
This method is commonly used. In addition, if members of the parent class can access the quilt class,Then you can use it like this and use the "super. member name in the parent class" method,But you often do not access the Member names in the parent class in this way.Constructor is a special method in constructor that is automatically called during object initialization.In the constructor, this and super also have various usage methods described above, and they also have special featur
indicates the value of the member variable of the parent class.
In addition, note that super. Name calls the value of the member variable,
Class country {string name = "xianfan"; string value (string name) {name = "China"; return name ;}} class cityextends country {string name; string Value (string name) {name = "Hefei"; super. value ("failed"); // when this method is not called, super. name returns the value of the member variable of the parent class nullsystem. out. println (name); system. o
commonly used. In addition, if the members of the parent class can access the quilt class, you can use it like this and use "super. in the parent class, but you often do not access the Member names in the parent class in this way.Constructor is a special method in constructor that is automatically called during object initialization. In the constructor, this and super also have various usage methods described above, and they also have special features. Please refer to the following example:
C
used. In addition, if the members of the parent class can access the quilt class, you can use it like this and use "super. in the parent class, but you often do not access the Member names in the parent class in this way.Constructor is a special method in constructor that is automatically called during object initialization. In the constructor, this and super also have various usage methods described above, and they also have special features. Please refer to the following example:
Class person
The instanceof in Java is used to determine if an instance is an instance of a class.Example: a instanceof B (A is an instance, B is a class name)If a is an instance of B, then: (a instanceof B) ==true and vice versa ==falsecode example:Package Javakeywords;class bird{//Parent class}class Bigbird extends Bird{//bird subclass}class Littlebird extends Bird implements Birdfly{//bird sub-class plus Birdfly interface}interface Birdfly{}public class Javakwinstanceof {public static void main (string[]
Label1 also interrupts all loops and returns to the Label1, but not heavy
New into the loop. In other words, it actually stops two loops completely.
Here is an example of a For loop:
: Labeledfor.java //java ' labeled for loop public class Labeledfor {NBSP;N Bsp public static void Main (string[] args) {
Nbsp;int i = 0; outer://Can ' t have statements here nbsp for (; true;) {//infinite loop inner://Can ' t have Statem Ents here for (; i
This uses the
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.