1. Summary of this week's study
Learning to object-oriented, will learn a lot of fragmented concepts and knowledge. Try to use mind mapping to organize these fragmented concepts and knowledge. Use a pen or paper or the tools below to draw the points of knowledge you learned this week. or photo upload.
2. Written work
1. Code Reading
PublicClassTest1 {Privateint i =1;This line cannot be modifiedPrivateStaticint j = 2; public static void main (string[] args) {Geti (); TEST1GETJ (); } public static void geti ( Out.println (i); } public static void GETJ ( Out.println (j); }}
can the above code be compiled and passed? Where does it go wrong? Trying to correct?
If you create 3 Test1 objects, there are several I in memory, a few J? Please analyze the reason?
/span>
2. What is the function of the constructor? What is the writing format? If a class does not write a constructor, does it have a constructor function? If a class has only a constructor with parameters, does it have a default constructor with no arguments?
The function is to initialize the class, the format is the same name as the class name and no return type, if a class does not write the constructor, the system will default to a parameterless constructor, if a class has a constructor with parameters, there is no default constructor without parameters.
3. java.lang.Math Why do I need new when I use a function of a class? What happens if new Math () generates errors? Analyze the cause?
Because the math class does not have a different internal state for each object, its methods and member variables are static.
4. What is an overload? What is a constructor overload? In the Java.lang.Math class cited out 1 examples of function overloading? How can I distinguish between two overloaded functions?
Overloads are multiple methods that have the same name, but have different parameters. Constructor overloading is the ability to write multiple constructors, with different parameter types and numbers.
5.final modified variables cannot be changed, why do the following code work correctly?
final int[] NUMBS= {1,2,3,4,5}; NUMBS[2] = 1;
因为final修饰引用类型变量,变量的值不能修改,但是变量指向的对象的值可以修改。
6.阅读代码EmployeeTest.java,回答:
Why are their properties private? What are the benefits of this design?
Employeeadd an parameterless constructor for the class, call its parameter constructor, set name to 雇员1 salary, 3000 and hireday for the month and day 2017年3月5日 . (Paste code)
EmployeeAdd an additional parameter constructor to the class, with only name and Salary,hideday as the current date. (Paste code)
(1) Private only allows access within the class and cannot be accessed externally.
3. Managing code with the code cloud
201521123035 the third week of Java Program Design Study summary