-2

This is the picture for question which i am asking Please look at this picture also to understand the code.

In the image which I have mentioned here. It shows the setObject method inside the Class A. (There are 2 classes 1 called class A and another Class B). Inside class a it has created a method called set B Object. I need someone to explain me what this code does. The teacher which teaches is very bad, he cant even speak english properly. Please if anyone can explain it to me. That would be a big help

I know how to write a normal Set method, but I am not sure of a SetMethod for a class.

smnt
  • 21
  • 2
  • 1
    You might want to check other questions like https://stackoverflow.com/questions/2036970/how-do-getters-and-setters-work – Progman Dec 20 '22 at 18:53
  • `this.BObject` stores a reference to the `classB` instance - and please don't learn those naming conventions, Java classes should start uppercase (`ClassB`), variable names start lowercase (`bObject`), it's incredibly confusing if you turn it around 180° – zapl Dec 20 '22 at 19:19
  • 1
    Please don't post images of code, errors, logs, or other text; see [ask] – Robert Dec 20 '22 at 19:23

1 Answers1

1

There's nothing special about this method.

Class A has a member of type Class B called BObject (BTW - this name doesn't follow Java's naming conventions). The setBObject methods gets an instance of classB and saves it to the data member in the classA instance, exactly the same as any other setter would do.

Mureinik
  • 297,002
  • 52
  • 306
  • 350