Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. public class Mememe {
  2. private static int m_AccessableInt; // доступно в StaticNestedMememe
  3. private int m_NotAccessableInt; // не доступно в StaticNestedMememe
  4. [...]
  5.  
  6. public static class StaticNestedMememe {
  7. [...]
  8. }
  9. }
  10.  
  11. Mememe.StaticNestedMememe nestedObject = new Mememe.StaticNestedMememe();
  12.  
  13. public class Mememe {
  14. public void calc(String requestPath) {
  15. class Сalculator{
  16. int calc() { return 0; }
  17. }
  18. }
  19. }
  20.  
  21. new Thread(new Runnable() {
  22. public void run() {
  23. ...
  24. }
  25. }).start();
  26.  
  27. public class OuterClass {
  28. public void method() { ... }
  29.  
  30. public class InnerClass {
  31. public void method() { ... }
  32.  
  33. public void anotherMethod() {
  34. method();
  35. }
  36. }
  37. }
  38.  
  39. OuterClass outer = new OuterClass();
  40. OuterClass.InnerClass innerClass = outer.new InnerClass();
  41.  
  42. public class Example {
  43.  
  44. public static int si = 0;
  45. private static int psi = 0;
  46. public final Inner inner;
  47. public int i = 0;
  48. private int pi = 0;
  49.  
  50. public Example() {
  51. inner = new Inner();
  52. }
  53.  
  54. public static class Nested {
  55.  
  56. int e;
  57.  
  58. public Nested() {
  59. e = Example.psi;
  60. e = Example.si;
  61. // а вот так нельзя
  62. // e = Example.this.pi;
  63. // e = Example.this.i;
  64. }
  65.  
  66. }
  67.  
  68. public class Inner {
  69. int e;
  70.  
  71. public Inner() {
  72. e = Example.psi;
  73. e = Example.si;
  74. e = Example.this.pi;
  75. e = Example.this.i;
  76. }
  77. }
  78.  
  79. }
  80.  
  81. class ExampleTwo {
  82. // Nested можно сразу
  83. Example.Nested nested = new Example.Nested();
  84.  
  85. Example.Inner inner;
  86. {
  87. // так нельзя, нужен объект Example
  88. // inner = new Example.Inner();
  89. // а так можно
  90. Example example = new Example();
  91. inner = example.inner;
  92. }
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement