Labs
Going forward, we will stop using the default, unnamed package. In fact, Eclipse warns us that its use is discouraged.
We'll also move away from simple package names like examples and labs, and develop the habit of using globally unique package names.
- In the
Packagesproject are some existing classes:
com
|_example
|_Helper.java
|_packages
|_Util.java
|_labs
|_Product.java
In the com.example.packages.labs package, create another class named ProductMain and replace its entire contents with the following:
public class ProductMain {
Product product;
public static void main(String[] args) {
ProductMain app = new ProductMain();
app.go();
}
public ProductMain() {
product = new Product();
}
public void go() {
Util.utilMethod();
Helper.helperMethod();
}
}
package and/or import statements so it will compile.
(Solution: com.example.packages.solutions.ProductMain)
- In your
com.example.packages.labspackage, create a new class namedProductMainStaticsand replace its entire contents with the following:
package com.example.packages.labs;
public class ProductMainStatics {
Product product;
public static void main(String[] args) {
ProductMainStatics app = new ProductMainStatics();
app.go();
}
public ProductMainStatics() {
product = new Product();
}
public void go() {
utilMethod();
helperMethod();
}
}
- Add
importstatements that will allow it to compile.
(Solution: com.example.packages.solutions.ProductMainStatics.java)