Results 1 to 5 of 5

Thread: Can a class in java be private, if yes what are implementations of it?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Oct 2007
    Answers
    2

    Question 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?


  2. #2
    Contributing Member
    Join Date
    Sep 2006
    Answers
    42

    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.


  3. #3
    Junior Member
    Join Date
    Oct 2007
    Answers
    1

    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.


  4. #4
    Junior Member
    Join Date
    Jun 2007
    Answers
    7

    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.


  5. #5
    Junior Member
    Join Date
    Dec 2007
    Answers
    3

    Thumbs up 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
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact