Java Study Day2

JavaSE day2:

Definition and control logical program and method JavaSE of
a logic control ( conditions must be a Boolean type, different from the C language )
1) sequentially performs
2) execution condition
1> if (condition) {...} 2> switch ( digital | enumeration | | character string) {...}
3) performs loop
1> while (condition) {...} 2> do { ...} while ( condition) 3> for (initialization statement; condition ; change statement)
. 4> form the foreach
eg: int a [] = { 1,2,3,4,5};
The first embodiment: for (int I = 0; I <a.length; I ++) {
the System. Out.println (a [I]);
}
the second embodiment: variable name value type: capacity
for (int V: a) {
System.out.println (V);
}
second, the method
defined in 1) methods syntax
defined method name return type identifier (parameter list) exception list
public static
call 2) a method
name of the method (argument);
3) other
signature methods: method parameter list name +
method overloading (overloading is the): method name the same parameter list (type, sequence number) different
4) supplementary
1> Method overloading is to have a unified approach to the class as a means of different types of data. The method of the same name exist, having different number of parameters / types. Overload (Overloading is the) is a polymorphism of a performance.
2> Java method overloading, is in a class can create multiple methods, they have the same name but with different parameters and different definitions. Decide when to call the method passed to them by the number of different parameters and parameter types what methods specific use, this is polymorphism.
3>, when overloaded, the method name to be the same, but not the same number and type of parameters, return type may be the same or different, can not return to the standard type for distinguishing overloaded methods.
Then let us turn to  rewrite (Overriding) redefine i.e.
polymorphisms between 1> parent class and subclasses of the parent class is redefined. If you define a method in a subclass and his father have the same name and parameters, we say that the method is rewritten (Overriding). In Java, a subclass can inherit the parent class's method, without having to rewrite the same way. But sometimes intact subclass does not want to inherit the parent class method, but to make certain changes, which need to rewrite methods. Method overrides method, also known as coverage.
2> if the method in the subclass having the same and a method name of the parent class, return type and parameter list, the new method overwrites the existing method. For the parent class any original way to use the super keyword, which quoted the father of the current class.
3> access privileges modified sub-class functions can not be less than the parent class;
it simply:
Overloaded: a class has a method A, you've created a method B in this class, method name as B and A , return type is the same, but different types or number of parameters, in which case B overloaded A.
For example:
public class the TestClass {
public static int Test (I int). 1 {return;}
static int Test public (a float F). 1 {return;}
}
rewritten: M a class inherits from another class N, N, there is a method A, when you write a Method B M, B of the method name, return and a values, and parameters are the same, then B rewritten A.
For example:
public class TestClass1 {
public int Test (I int). 1 {return;}
}
public class TestClass2 the extends TestClass1 {
public int Test (I int) 2 {return;}
}
. 5) recursively
attach enhance cognitive exercises these codes (codes are written in Notepad ++, compile and run the command line):
Java Study Day2
Java Study Day2
Java Study Day2
Java Study Day2
Java Study Day2
Java Study Day2
Java Study Day2
Java Study Day2
Java Study Day2
Java Study Day2

Guess you like

Origin blog.51cto.com/14235507/2421557