Questions tagged [access-specifier]

The access specifier in an object-oriented language determines how a class restricts access to its members.

The access specifier in an object-oriented language determines how a class restricts access to its members.

The usual access specifiers are private, protected and public.

  • A class member whose access specifier is private can only be used by instances of that class.
  • A class member whose access specifier is protected can only be used by some other classes.
    Usually this means that access to these members is granted only to subclasses, but this is not a hard-and-fast rule. In Java, for example, classes that are in the same package also have access to each other's protected members.
  • A class member whose access specifier is public can be used by all other classes in the program.

You can use this tag for questions about how access to the members of your class is resolved.

242 questions
-5
votes
1 answer

Why can I define only default and static methods inside a java interface?

Why can I define only default and static methods inside a java interface,while other access modifiers like protected and public having much more privilege than default can't be used? interface int1 { default void add(int a, int b) { …
-5
votes
5 answers

Explain the output of the program in java ?

In this program Is it possible to use the access specifier inside the method class AccessTest{ int i; public static void main (String... str) { int i; private int a = 1; protected int b = 1; public int c = 1; System.out.print…
Shivam
  • 674
  • 1
  • 4
  • 25
1 2 3
16
17