1. When we create a static method in a subclass, it does not overwrite the static method of the same name in the parent class.
2. When overriding a method of a parent class in a subclass, you can extend the method permissions in the parent class, and you cannot narrow the permissions of the parent method.
3. When the object of the parent class points to the entity object of the child class, the method of the subclass that is executed, that is, the overwrite has occurred. That is, the object of the parent class can still access the members of the child class. If the child class does not have the same method as the parent class, an error is compiled.
4. instanceof to test whether a specified object is an instance of the specified class or its subclasses.
5.abstract cannot be decorated in the same way as private, static final native.
2014/12/25
Java local variables have no default values and must be assigned an initial value.
The type of the constructed method is the type of the class and cannot be void.
A subclass inherits a method that can only manipulate member variables that subclass inherits and hides (Super).
The variables in the parent class are hidden from the subclass, even if the same variable is defined. Super can call a hidden parent class variable.
Subclasses inherit the parent class's stance method, must be static, and cannot be overwritten.
The method in Java must be returned or the error is not void.
The member variable has an initial value and does not assign an error.
Protected class A
Private Class A
It's all wrong.
A variable defined as private cannot be assigned a value in another class.
A variable defined as protected can be assigned a value in another class.
You cannot use final and abstract to modify the same method at the same time
The subclass constructor method can be directly assigned with the member variables of the parent class without having to define it, as the parent class has an int i; In the constructor of a subclass it can be directly to the "i=0;" Assigned value.
The constructor method of the parent class must be called before the constructor of the subclass is executed.
Here is a static block,
static {
}
Static blocks are characterized by the execution of class loading, first of all class loading, a program to run, the first to load the code into memory, right? Then can go to communicate with the CPU, this is von Neumann computer stipulation. Java is also the same, Java. class bytecode file to be executed, the first to load into memory, by the class loader to load bytecode file code into memory, this step is called class loading, this is the first thing to do.
public class Test {
static {
System.out.println ("I am a static block");
}
}
When creating an object of the Test class, such as New Test (), the first is the class load, then the new object, the static block executes when the class is loaded, which means that the static block executes before the new object, and a class is loaded the first time it is used. Then the entire application life cycle will not be loaded again, loading this time, so this means that the static block is executed once, will not be executed twice!
1 public class test {2 public test () {//constructor Method 3 System.out.println ("I am the constructor, I will execute when I create the object, I execute it, the object is created"}5 6 Static
{7 System.out.println ("I am a static block, I execute it when the class loads, and only do this once"
}9}
Then this:
New Test ();
New Test ();
You will find that the information of the static block is printed first, then the construction method information is printed, and then the new Test () is printed, only the information of the construction method is plotted, this example proves that what I said above is right!
1 classT1 {2 3 int i = 0; 4 5 public voidA1 () {6 7 System.out.println ("T1 a1=" + i); 8 9 }10 one public void A2 () {System.out.println ("T1 a2=" + i); }16 +
}20 class T2 extends
t1{24 int i = 2 ; all public void A2 () {System.out.println ("T2 A 2= "+ i); }32, }36, and the public class E {All public static void Main (String [] args) {T1 test = new T2 (); test.a1 (); System.out.println test.a2 (); + test.i); test = (T2) test;52 System.out.println ("test.i=" + test.i); 54 55 56 57 System.out.println ("-----------" ), T2 test2 = new T2 (), test2.a1 (); 2 (); System.out.println ("test.i=" + test2.i),}72, span>
Java Exam Note One