How to avoid B Class object creation from outside world, and allow through only A Class
<p>How to avoid B Class object creation from outside world, and allow through only A Class ?</p>

<p>I have 2 classes</p>

<pre><code>public class A {
    B obj = null;
    public A() {
        obj = new B();
    }        
    public void methodA () {
        obj.methodB();
    }        
    // other methods
}

public class B {
    public void methodB () {
        // some logic            
    }
    //other methods
}

public class Client {
    public static void main (String s[]) {
        // Valid Call            
        A obj = new A();
        obj.methodA();  // Since methodB is called internally

        // Invalid Call , How to restrict this B object creation here ?
        B objB = new B();
        objB.methodB();

    }
}
</code></pre>
