0

I am having great difficulties understanding this construct

 public class MyBucket extends bucket {
   private double var1;
   private MyShovel Shovel; <- this is the problem here

   public MyBucket(int volume, MyShovel Shovel) {

      Some code here

   }
  }

I cannot understand what private MyShovel Shovel is in Java terminology. It is a class defined in my project but I cannot determine what it is called in the Java world. Can someone please help me define it so I can research what it is. This is production code and it works. Just cannot figure out the official Java name for that construct.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Jrobot
  • 17
  • 2
  • 1
    `Shovel` is a *private*, *instance level* field of type `MyShovel` in `MyBucket` class. Note : `Shovel` is just a *reference* to an instance of `MyShovel` – TheLostMind Jan 15 '15 at 07:10
  • 1
    `shovel` is an instance variable, member or field of `MyBucket` – MadProgrammer Jan 15 '15 at 07:10
  • *member variable* or *field* By Java naming conventions, it should be `shovel`, not `Shovel`. Variables should start with a lowercase letter; types start with uppercase. – erickson Jan 15 '15 at 07:12
  • Hmm, just change it to `MyShovel shovel`, and you will get it! – Pham Trung Jan 15 '15 at 07:28

2 Answers2

1

Shovel is a (private) member. Its type is MyShovel. This means that every instance of MyBucket contains a reference to a MyShovel object, which can be referenced only from within the class, by the name Shovel.

Note that this declaration does not follow java naming conventions. In the proper conventions it would have been called myShovel, in lowerCamelCase.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

Shovel is just a variable. It is an instance of MyShovel. MyShovel would be a Class that represents a virtual shovel. Since it is a global variable, or field, in MyBucket this means that each MyBucket also would have MyShovel inside of it.

In the code you provided it is undefined and has no value. Since it is private only methods in MyBucket can access it. The MyBucket constructor takes a MyShovel parameter and is most likely what Shovel is set to.

You can think of it like this: Every MyBucket must have a MyShovel inside of it to make it work. So when creating a MyBucket you put a MyShovel inside of it. Shovel is the space that that particular MyShovel will be stored.

As others mentioned it should be named "shovel" for naming convention.

Troy Stopera
  • 302
  • 3
  • 15