Can a class in java be private, if yes what are implementations of it?
Can a class in java be private, if yes what are implementations of it?
Re: Can a class in java be private, if yes what are implementations of it?
A normal class in Java cannot be private, but an inner class can be private. Inner classes are generally used in Swings to add listeners for various components.
Regards,
Sahil.
Re: Can a class in java be private, if yes what are implementations of it?
we can't declare top level class as private(only public).we can declare inner classes as private.if declare any methods and variable declared in private class we can access those methods and variable with in that scope directly.if u want access out of that class by using constructor we can access.
Re: Can a class in java be private, if yes what are implementations of it?
No top level class in java can't be declared as private only public, abstract and final are permitted.
Re: Can a class in java be private, if yes what are implementations of it?
Java Inner Classes
class A {
private a;
class B {
private b;
void f() {
b = a+a; // accessing pvt. var of A
}
public g(){
B myObj = new B();
myObj.f();
int x = myObj.b; // accessing pvt. var
of A
}
}