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
  • 298,294
  • 41
  • 291
  • 462
silly questions
  • 337
  • 6
  • 13

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
  • 64,900
  • 8
  • 112
  • 148