Merge pull request #3392 from sirishrenukumar/srenukumar/static_class
Static class example (review comments addressed)
This commit is contained in:
commit
023b3ae9f7
|
@ -0,0 +1,33 @@
|
||||||
|
package com.baeldung.staticclass;
|
||||||
|
|
||||||
|
public class Pizza {
|
||||||
|
|
||||||
|
private static String cookedCount;
|
||||||
|
private boolean isThinCrust;
|
||||||
|
|
||||||
|
// Accessible globally
|
||||||
|
public static class PizzaSalesCounter {
|
||||||
|
|
||||||
|
private static String orderedCount;
|
||||||
|
public static String deliveredCount;
|
||||||
|
|
||||||
|
PizzaSalesCounter() {
|
||||||
|
System.out.println("Static field of enclosing class is "
|
||||||
|
+ Pizza.cookedCount);
|
||||||
|
System.out.println("Non-static field of enclosing class is "
|
||||||
|
+ new Pizza().isThinCrust);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Pizza() {
|
||||||
|
System.out.println("Non private static field of static class is "
|
||||||
|
+ PizzaSalesCounter.deliveredCount);
|
||||||
|
System.out.println("Private static field of static class is "
|
||||||
|
+ PizzaSalesCounter.orderedCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] a) {
|
||||||
|
// Create instance of the static class without an instance of enclosing class
|
||||||
|
new Pizza.PizzaSalesCounter();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue