201521123092 the third week of Java Program Design Study summary

Source: Internet
Author: User

#1. This chapter is a summary of your study of the knowledge of this chapter.

#2. Written work

**q1. Code Reading

PublicClassTest1 {Privateint i =1;This line cannot be modifiedPrivatestatic int 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?

A: The above code cannot be compiled through.

1.TESTLGETJ () error, the code does not have this function, you can change to private static void TEST1GETJ ().

 2.system.out.println (i) error. I is not a static variable, remove the static.

If you create three Test1 objects, the memory will have 3 i,1 J. A non-static object has a different storage space than the static object, and static has only one storage space for each class, and the Test1 class creates a new storage space for the new object.

**q2. What is the use of constructors? 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?

A: 1. Constructors can be used to initialize the class.

2. Write the format public xxx () {}

3. There is a constructor, is the default constructor, is the programming program automatically established.

4. If a class has only a constructor with parameters, it does not have a default constructor with no arguments

**q3. java.lang.Mathwhen using a function of a class, why don't you need new? What happens if new Math () generates errors? Analyze the cause?

Answer: 1. The math method is static and does not need to be rebuilt when called, and can be accessed directly from the class name.

2. Use new to error, indicating that the constructor is not visible.

**q4. What is overloading? What is a constructor overload? How can I distinguish between two overloaded functions?

A: 1. Overloading, that is, the method name is the same, the number of parameters or different types

2. Constructor overloading: A class can have more than one constructor, and each constructor has a different argument list

3. Differentiate two overloaded functions according to the type, number, and order of the parameters in the overloaded function.

**q5. The final modified variable cannot be changed, why does the following code work?

Final int[] numbs= {1,2,3,4,5}; numbs[2] = 1;

A: After the final decorated reference type variable is assigned, you cannot point to another object. However, the value of the intrinsic property of the referenced object can be changed.

**q6. Read the code Employeetest.java and answer:

    1. Why are their properties private? What are the benefits of this design?
    2. 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)
    3. EmployeeAdd an additional parameter constructor to the class, with only name and Salary,hideday as the current date. (Paste code)

A: 1. Define the property as private to avoid external manipulation of it.

2. Public Employee() {

This ("Employee 1",3,5);

}

3. Public Employee(String N,double s) {

Name=n;

Salary=s;

             calendar RightNow = Calendar. getinstance ();

Hireday=rightnow.gettime ();

}

**q7. Write function public static Boolean ismondaytofriday ()

function: Judging today if it is Monday to Friday, direct output such as "work Time" and return true, otherwise output "break time". Tip: Use LocalDateTime, DayOfWeek.

For:

public static Boolean Ismondaytofriday ()
{
LocalDateTime LocalDateTime = Localdatetime.now ();

DayofWeek day = Localdatetime.getdayofweek ();

int Day1=day.getvalue ();

if (day1 >= 1 && Day 1<= 5) {

System.out.println ("Working:" +localdatetime);
return true;
}
else return false;
}

#3. Code Cloud Codes Submission

In the Code cloud Project, select statistics-commits history-set time period, and then search for and

#4. PTA Experiment (experimental Summary)

Lab 1: Use Eclipse to automatically generate Settter,getter and ToString functions, which reduces the time to code and improves efficiency.

Experiment 2: Static initialization is used on the basis of experiment 1.

Experiment 3: When using Math.PI, because radius is int, the result needs to be converted to int type.


201521123092 the third week of Java Program Design Study summary

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.