0

Sample code:

class A {
    public doSomethingFancy() {
         .....
         doJOb();
    }
    private doJob() {
        B b  = new B();
    }

    private class B {
    }
}

class B is only needed for class A.Or is only used in class A.

Is there need to declare class B as static ? yes/no Why?

user207421
  • 305,947
  • 44
  • 307
  • 483
silly questions
  • 357
  • 6
  • 14

1 Answers1

0

You declare B static if it doesn't need access to the A object it was created for.

You declare B private if only A needs to use it, or other clients only use it via its implemented interfaces.

Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157