-
Junior Member
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?
-
Contributing Member
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.
-
Junior Member
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.
-
Junior Member
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.
-
Junior Member
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
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules