About 551,000 results
Open links in new tab
  1. What is the difference between public, protected, package-private …

    Oct 19, 2008 · In Java, are there clear rules on when to use each of access modifiers, namely the default (package private), public, protected and private, while making class and interface and …

  2. java - Private class declaration - Stack Overflow

    I was wondering about a situation where you add a main method inside of the private class and access all of the other classes - public, protected, package-private - from within.

  3. java - Why can't we define a top level class as private ... - Stack ...

    Dec 16, 2009 · Why does Java not allow a top level class to be declared as private? Is there any other reason other than "We can't access a private class"?

  4. Why do we declare Private variables in Java? - Stack Overflow

    Feb 16, 2018 · I'm confused because all I keep hearing is that private variables in Java are supposed to protect the code or the variable. But if anybody has access to the code, then it …

  5. java - When would I want to make my private class static ... - Stack ...

    Mar 26, 2014 · In general, are there any benefits in declaring a private class as static? In what cases would I want to use one of the following over the other? private static class Foo { ... } vs …

  6. java - How do I test a class that has private methods, fields or …

    Aug 29, 2008 · How do I use JUnit to test a class that has internal private methods, fields or nested classes? It seems bad to change the access modifier for a method just to be able to …

  7. Can we declare class as 'private' in java? - Stack Overflow

    Nov 27, 2016 · A class is a user-defined (custom) datatype and you can't declare a class in Java as private, but if you do not want to expose a particular user-defined data type (class) outside …

  8. java - Do subclasses inherit private fields? - Stack Overflow

    A private class member or constructor is accessible only within the body of the top level class (§7.6) that encloses the declaration of the member or constructor.

  9. How to use a private method in Java - Stack Overflow

    Feb 4, 2013 · I am given a class that has a private method say setCoors(int x, int y). The constructor of that class has the setCoors in it too. In a different class, I want to have a method …

  10. What is the use of a private static variable in Java?

    Sep 2, 2011 · The private keyword will allow the use for the variable access within the class and static means we can access the variable in a static method. You may need this cause a non …