5.2

Object-oriented (on):
  1, what is object-oriented, what is process-oriented?

              Object-oriented is what method is used to do something, this thing is the object, the method does not matter

              Process-oriented is what method is used to do something, this method is process
  2, class, object, member variable (attribute, static attribute), member method (method, dynamic attribute), the meaning of local variables respectively?
  3, the characteristics of object-oriented What?
    Encapsulate
      private (public)
    inheritance

    Polymorphism Variable names with the same name have different expressions
      Cut
      Cut

  4. How to create an object in a program? (First define a class)
    Class body
      Scope of member variables (the whole class)
    Exercise: Write a class of Person, make it have a method that can be called, and print out the name and age
        My name is..., how old are you?

    The relationship between classes and classes
      Association relationship (not good for the next definition to describe the association relationship, weaker relationship)

        A parameter of a method in one class is an object of another class
        A member variable in one class is an object of another class

      *         Inheritance           relationship (extends keyword)           what
        is a           kind         of           what           ?
      Aggregation       relationship
        ???







   5, How are member variables initialized in the class?
      byte 0
      short 0
      int 0
      long 0L
      float 0.0F
      double 0.0D
      boolean false
      char '/u0000'
      reference type null
      (reference type is: all classes, all interfaces, all array of )  

    6. How to design a class better?
      Appropriate methods appear in appropriate classes.
    7. What is class encapsulation?
      Member variables modified by the private keyword can only be used in the current class. You need to use get, set

public class Emp {

    // Constructor 
/*     public Emp() {
        System.out.println("Construction method of empty parameter");
        name = "Tom";
        sal = 12345;
        age = 30;
    }*/
    public Emp() {}
    
    public Emp(String _name, int _age) { //Method exposed to the outside world
        System.out.println( "The constructor with parameters was called" );
        name = _name;
        age = _age;
    }

    private String name; // name 
    private  double sal; // salary 
    private  int age; // 0 - 120 1000

    public  void introduce () {
        System.out.println( "My name is" + name + ", salary is: " + sal + "this year" + age + "year" );
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

}

        8. What is a constructor? Overloading of a
      constructor     ? // The method name is the same, but the parameter list         is different         . The name of the constructor is exactly the same as the name of the class.         3. When defining a class, if no constructor is written, a constructor with empty parameters will be generated by default.         4. When there is a constructor with parameters defined in a class, then the empty parameter constructor will disappear





       

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325305323&siteId=291194637
5.2
5.2