Java BASICS (7) Object-oriented (2), java basics object-oriented

Source: Internet
Author: User

Java BASICS (7) Object-oriented (2), java basics object-oriented

Here are some of the knowledge points and code I summarized in my previous class. Most of the notes I think are very good and classic, sincerely hope that these will help those who want to learn!

It is inconvenient to upload code by module. There are also many things, and they are also clear! If you need it, you can leave your email in the comments. I will certainly send it to you for free! Thank you for making progress on this platform !! Remember that programmers are selfless !!!

Also very welcome to my blog to watch blog address: http://www.cnblogs.com/duscl/

 

/* 5: private keywords (master) (1) private meaning, can modify member variables and member methods (2) features: the modified private member can only be accessed in this class (3) private applications: when another class is written in the future: give all the member variables to private and provide the corresponding getXxx ()/setXxx () method 6: this keyword (master) (1) indicates the reference object of the current class. Remember: if the object calls A method, this inside the method represents the application scenario of the object (2) this: A: solves the problem of hiding member variables in local variables B: in fact, this has other applications, which will be explained tomorrow. 7: Constructor (master) (1) function: used to initialize object data (2) Format: A: The method name and class name are the same B: No return value type, even void cannot have C: No return value thinking question: can there be a return statement in the constructor? Yes. But we can write it like this: return; in fact, at the end of any void method, you can write: return; (3) constructor: if the constructor method is not written, the system will provide a default constructor without parameters. B: If the constructor method is provided, the system will not provide the default constructor, to use the non-argument constructor, you must give it by yourself. Recommendation: manually construct a method without parameters. (4) assign values to member variables A: setXxx () B: constructor with parameters (5) standard case class Student {private String name; private int age; public Student () {} public Student (String name, int age) {this. name = name; this. age = age;} public String getName () {return name;} public void setName (String name) {this. name = name;} public int getAge () {return age;} public void setAge (int age) {this. age = age ;}} test: class StudentDemo {publi C static void main (String [] args) {// method 1 Student s1 = new Student (); s1.setName ("Lin Qingxia"); s1.setAge (27); System. out. println (s1.getName () + "---" + s1.getAge (); // method 2 Student s2 = new Student ("Liu Yi", 30); System. out. println (s2.getName () + "---" + s2.getAge ();} 8: Code: Student s = new Student (); what have you done? (Understanding) (1) set Student. class file loaded to memory (2) in stack memory for s open space (3) in heap memory for student object application space (4) to student member variables for default initialization. Null, 0 (5) displays the student's member variables for initialization. Lin Qingxia, 27 (6) initialize the member variables through the constructor. Liu Yi, 30 (7) after the object is constructed, assign the address value to the s Variable 9: Object-oriented exercises (mastery) (1) Definition and testing of standard mobile phone classes (2) the Demo class has a summation method. The Test class is used for testing. When do I define a member variable? This variable is used to describe a class. (3) rectangular case (4) Employee case (5) MyMath case (provide addition, subtraction, multiplication, division, and test by yourself) 10: static keyword (understanding) (1) static meaning. You can modify member variables and member methods. (2) Static features: A: loading B with class loading: priority and object existence C: shared by all objects of the class, which is also the basis for us to determine whether to use static data. Example: Question about water dispenser and water cup D: class name call can be called either through the object name or through the class name. It is recommended to call by class name. (3) Static Memory diagram static content in the static area of the Method Area (4) Static considerations; A: no such object B in the static method: static can only access static (Code tested) (5) differences between static variables and member variables A: different static variables: Class, Class variable member variables: object, object variables, instance variable B: memory location different static variables: static zone member variables in the Method Area: heap memory C: different static variables with different lifecycles: static variables are loaded with classes, the member variable disappears with the disappearance of the class: The member variable exists with the creation of the object, and disappears with the disappearance of the Object D: Call different static variables: can be called through the Object Name, you can also use the class name to call the member variable: You can only call the main method through the Object Name (6) the main method is static public: Maximum permission static: No need to create an object call void: the return value does not make sense to jvm. main is a common name. String [] args: can receive data, the flexible format of the provider: java MainDemo hello world java MainDemo 10 20 30 *\

 

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.