I'd like to ask you in detail about . in Java.

Asked 2 years ago, Updated 2 years ago, 94 views

I'm a student studying Java Until now, "." When you perform a method with an object.method, This.I thought it was only used to classify variables with variables. Then object.variable=1; I Variable type Variable name = object.Variables; And we found that it could be used for initialization like this. In more detail the conditions and conditions applicable to I'd like to know if it's used in another case

java programming

2022-09-22 18:45

1 Answers

left side .right side

. is an operator to access the right-hand side (RHS) name that belongs to the left-hand side (LHS). The left side can have classes, variables, and objects. The right-hand side must have names such as type, method, and field belonging to the left-hand side.

This means that the name on the right-hand side exists on the left-hand side to help you access it.

If you think about it in Korean, you can think of it as 's.

class Person {
    public void hello() { System.out.println("hello"); }
}

If you want to call a method called hello() when there is a class called Person as above, you will write it as follows.

Person p = new Person();
p.hello();

At this time, p.hello(); is to call p's hello(). p is actually any object created by newPerson(), so it would mean calling hello() of the object pointed by the p variable.


2022-09-22 18:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.