What does this mean: defining a class with a method that receives an object of type class?

Suppose we have class class1.

Class1 has a method called method1, and this method gets an object of type class1. eg:

public class class1
{
     //instance members
     // property methods

    public void method1(class1 obj)
    {
         //...........
    }
}

What does this mean: a method gets an object of this class type? In what scenarios can this be used?

+3
source share
4 answers

What does this mean: a method gets an object of this class type?

Yeah. There is nothing special about this. Why are you asking?

. Union, Set. , . Eat, . Concatenate, . .

+8

, :

public class Node
{
    private m_childNodes List<Node>;
    // ...
    public AppendChild(Node child)
    {
        m_childNodes.Add(child);
    }

}
+3

It allows you to method1work with an external instance class1.

+2
source

An object of type "Class1" is required.

For example, you can do:

Class1 myClass = new Class1();
Class1 yourClass = new Class1();
myClass.method1(yourClass);

Each variable declared by the class Class1 is its own object with its own functions and members.

+2
source

Source: https://habr.com/ru/post/1734655/


All Articles