29 lines
813 B
Java
29 lines
813 B
Java
// innerclasses/Parcel6.java
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
// Nesting a class within a scope.
|
|
|
|
public class Parcel6 {
|
|
private void internalTracking(boolean b) {
|
|
if(b) {
|
|
class TrackingSlip {
|
|
private String id;
|
|
TrackingSlip(String s) {
|
|
id = s;
|
|
}
|
|
String getSlip() { return id; }
|
|
}
|
|
TrackingSlip ts = new TrackingSlip("slip");
|
|
String s = ts.getSlip();
|
|
}
|
|
// Can't use it here! Out of scope:
|
|
//! TrackingSlip ts = new TrackingSlip("x");
|
|
}
|
|
public void track() { internalTracking(true); }
|
|
public static void main(String[] args) {
|
|
Parcel6 p = new Parcel6();
|
|
p.track();
|
|
}
|
|
}
|