Home > other >  How can we make nested packages like this in java?
How can we make nested packages like this in java?

Time:01-16

So this article i am following has this guy nesting packages like this. How can I achieve the same result?

I tried to nest a package like this but I was unable to make it like the image.

CodePudding user response:

As @Sanjeevan is using Eclipse, here is a way to nest packages in Eclipse;

  1. Right click the root folder of your desired "nested" package branch,
  2. Select New > Folder,
  3. Type a name for the package and click finish (in this example, the name of the first folder is parent),
  4. Right click the parent folder.
  5. Select New > Folder,
  6. Type a name for the package and click finish (in this example, the name of the second folder is child),
  7. You will see a folder named parent.child. This is your nested "package". When you create a new class under this folder, either package parent.child; will be added automatically to the top of your classes, or you must add them manually.

CodePudding user response:

The solution was to type the sub packages with a '.' So if we have a main package say 'com.main' and we wanted to make sure we wanted to create a sub package for that we should write it as 'com.main.sub'

and to make sure we have it visually follow that, you can read this. https://stackoverflow.com/a/25378808/20406462

  • Related