Can a constructor call other methods of this class?

Updated on healthy 2024-02-11
7 answers
  1. Anonymous users2024-02-06

    Yes, it can call the private properties of this class, so why not call other methods of this class? And after triing, it does call.

    public class person {private string name = "aa";

    public person(){

    setname("dsd");

    public void setname(string name) {= name;

    public static void main(string args)

    person p=new person();

  2. Anonymous users2024-02-05

    No, you can only adjust the other constructors of this class or the constructors of its parent class.

  3. Anonymous users2024-02-04

    Yes, you can call other methods ...... this class

  4. Anonymous users2024-02-03

    It is called in the form this(), with the actual parameters of the other constructed lists in parentheses.

    Note: The first article of the executable statement must be written in this constructor.

  5. Anonymous users2024-02-02

    The parent class member variable should be used in a child class, not this.

  6. Anonymous users2024-02-01

    1. You need to know what the constructor is used for, and the constructor is used to construct object instances. A member method, on the other hand, is used to perform a function and requires an object instance to call it. So the order is:

    The constructor is executed to obtain an object instance, and the object instance calls a member method. So it's not possible to call the constructor in the member method, I don't know why you'd want to do that.

    2. super can only be placed in the first line of the subclass construction method. There's no need to call this method anywhere else.

    3. If the access rights of the member variables of the parent class are public and protected, they can be assigned in this way. However, the general access rights should be set to private

  7. Anonymous users2024-01-31

    First question:

    The first method in the left figure is the constructor, and the show method is the member method, the member method can be used in the constructor, and the constructor cannot be called explicitly, the constructor will be called in the new operator, that is, in the show method, new student(); Of course, in the above example, if the show method is called in the constructor and the student method is new, it will cause an endless loop, and the program will crash after running out of memory.

    Second question:

    The child class has all the member variables and member methods of the parent class, so the member variables of the parent class used in the child class should be referenced with this, not super, and the method name can be written directly when referencing the parent class member method, without using this reference, in addition, there can also be a method with the same name as the parent class in the child class, which is regarded as a method override, and the method with the same name of the child class will replace the parent method, that is, the method of the parent class does not work.

Related questions
9 answers2024-02-11

Delusion is three hearts, three hearts can not be obtained, when the Buddha is suppressed, the Buddha needs to listen to the ears, listen to the heart can be one, delusions are self-resting. And usually train yourself to recite the Buddha at 26 o'clock, when chanting the Buddha, listen to the ears, but although it is silent recitation, but there is the sound of chanting the Buddha in the ear, if the delusion is up, the ear will not hear, you need to raise your awareness to return to the hearing, according to this practice, you will be able to recite the Buddha's samadhi for three years, and get rid of life and death.

10 answers2024-02-11

If you want to improve your own emotions, you must make your emotions less easily fluctuated by others, because, for the sake of other people's emotions, people who affect their own emotions are really stupid. In fact, it is best to guide yourself step by step, and not to drill the horns.

5 answers2024-02-11

1.Fill yourself up, whether you're a student or a worker, and don't give yourself any free time. >>>More

9 answers2024-02-11

People who like sports have several sports that they are more passionate about, some people like to run, some people like to swim, some people like to climb mountains, some people like to exercise in the indoor gym, and some people like to run on the road outdoors, some people are for **, some people say that it is because of love, and some people want to shape a perfect body, so exercise is something that everyone should insist on. It can also be said to be the hottest topic at present, many people do not hesitate to spend a lot of money to report the training camp, or the gym, but because of the time problem, many people may insist on a meal and give up, very few can persevere, and it is also a good exercise for themselves to really stick to it, whether it is the body or personal will, but in addition to the gym, there are some simple exercises, which can also help us ** and help us lose weight quicklyThe first is running, the second is jumping rope, and there are some fat-burning exercises. >>>More

13 answers2024-02-11

You'd better see a doctor!

By: Favorite Toyota - Jianghu Rookie Level 4 3-30 20:31Find something else to do! >>>More