What is difference between access modifier and access specifier in java

+1 vote
This question was asked in my interview technical round. I am a little bit confused

can someone explain about this briefly in detail?

Thanks in advance
Feb 14, 2019 in Java by sathish kannan
70,433 views

7 answers to this question.

+1 vote
Best answer

Access Specifier:- This can be understood as the access you provide to your code in Java whether other classes can access your code or not.

E.g. public, private, protected and default.

Access Modifier:- Java provides both Access Specifier and Access Modifiers for creating access to your Java code for other classes. Here modifier is also used to do the same task but there are limitations.

  1. Class Modifier:
    • abstract :- This defines the restriction such that objects cannot be created.
    • final:- This restricts a class from being inherited.
    • strictfp:- it is related to the checking of floating point values irrespective of OS.
  2. Variable Modifier:
    • static:no object creation required
    • final: cannot be reassigned
    • transient: it is not serialized
    • volatile: the values are liable for change

Hope you got the difference now.

answered Feb 14, 2019 by Priyaj
• 58,100 points
But when we write public in our main heading of java program like public class and then in public static void main what then public indicates its access specifier or access modifier?
Not understood please explain
is access specifies also called access modifiers

Hey @Ardhendu Bhat,

Let's see an example below on Access Specifier:

 1. public void display() { }

2. private void display() { }

Above, there are two display() methods with public and private. These two words give permissions to other classes to access display() method.

 public means any class from anywhere can access it.

 private means not accessible to other classes; the method can be used by the same class (in which it is declared, like a private property used by the same family for which it belongs). Now I think it is clear. The public and private are known as access specifiers because they specify access.

There are four access specifiers Java supports, publicprotecteddefault (not specified at all) and private with different access restrictions. 

Access Modifier

Let us see an example with the help of the code below:

class Exam

{

public void Test() { }

}

class Result extends Exam

{

public void Test() { }

}

Here, In the above code, the Test() method of Exam class is overridden by Result class. In factResult class is at liberty to override or not. Now let us apply a small modifier to Test()method of Exam class.

Let us see one another example:

class Exam

{

public final void Test() { }

}

class Result extends Exam

{

public void Test) { }

}

In the superclass Exam, observe, the Test() method is added with the final keyword. In the superclass, if a method is declared as final, it cannot be overridden by a subclass. That is why the superclass by declaring a method as final does not allow the subclass to override. This is the modification given to the method in the superclass with the finalfinal is known as an access modifier.

I hope the above explanation will be helpful for you.

0 votes
Both are the same thing in Java. The only difference is that specifiers are liberal and modifiers are strict.
answered Feb 14, 2019 by Shashank
• 1,370 points
If both are same then why there are two concepts discussed separately?
They are similar concepts but not same.
Both are different access specifier is default, public, private, and protected whereas access modifier is final,static,strictfp, transient, abstract, native, synchronised,and volatile
0 votes
Java provides a default specifier which is used when no access modifier is present. Any class, field, method or constructor that has no declared access modifier is accessible only by classes in the same package. The default modifier is not used for fields and methods within an interface.
answered Feb 28, 2019 by Uk
0 votes
Access Specifier is used to provide your code in Java whether other classes can access your code or not.

Access Modifier provides both Access Specifier and Access Modifiers for creating access to your Java code for other classes. Here modifier is also used to do the same task but there are limitations.
answered Feb 28, 2019 by Pratosh kumar
0 votes

There is no difference between access specifier and access modifier in Java. They both mean the same. Access modifier is the new and official term used instead of access specifier. Java provides four access modifiers to set access levels for classes, variables, methods and constructors.

answered Dec 16, 2020 by trafoos
• 140 points
0 votes

Java provides entities called “Access Modifiers or access specifiers” that help us to restrict the scope or visibility of a package, class, constructor, methods, variables, or other data members. These access modifiers are also called “Visibility Specifiers”.

Java access modifier specifies which classes can access a given class and its fields, constructors and methods. Access modifiers can be specified separately for a class, its constructors, fields and methods. ... Classes, fields, constructors and methods can have one of four different Java access modifiers: private.

answered Dec 16, 2020 by Rajiv
• 8,910 points
0 votes

Access modifiers are the keywords which are used with classes, variables, methods and constructors to control their level of access. Java has four access modifiers:

  • Default : When no access modifier is specified, it is treated as default modifier. Its scope is limited within the package.
  • Public: The word itself indicates that it has scope everywhere, i.e; it is visible everywhere even outside the package.
  • Private: It has scope only within the class
  • Protected : Its scope limits within the package and all sub classes.

Non-access modifiers are those keywords which do not have anything related to the level of access but they provide a special functionality when specified.

  • Final: Final keyword can be used with variable, method or class. It prevents from its content from being modified. When declared with class, it prevents the class from being extended.
  • Static: Static modifier is used with class variables and methods which can be accessed without instance of class. Static variables has only single storage. All objects share the single storage of static variable. They can be accessed directly without any object. Static methods can also be declared. main() method is the popular static method we have. Static blocks can also be declared and are executed before main() method.
  • abstract: abstract can be used with class and methods. An abstract class can never be instantiated and its purpose is only to be extended. Abstract methods are declared without body and ends with semicolon. If a class contains an abstract method, it should also be specified as abstract. A class which extends an abstract class must implement all of its abstract methods.
  • Synchronized: It indicates that the method can be accessed only by one thread at a time.
  • Transient : An instance variable is marked transient to indicate the JVM to skip the particular variable when serializing the object containing it.
  • Volatile: The Java volatile keyword is used to mark a Java variable as "being stored in main memory". More precisely that means, that every read of a volatile variable will be read from the computer's main memory, and not from the CPU cache, and that every write to a volatile variable will be written to main memory, and not just to the CPU cache.
  • strictfp: It is used so that the floating-point precision do not change from one platform to another platform. Java strictfp keyword ensures that you will get the same result on every platform if you perform operations in the floating-point variable.
answered Dec 16, 2020 by Gitika
• 65,890 points

Related Questions In Java

0 votes
2 answers

What is the difference between Set and List in java?

List is an ordered sequence of elements. ...READ MORE

answered Apr 26, 2018 in Java by Akrati
• 3,190 points
63,263 views
0 votes
2 answers

What is the difference between getAttribute() and getParameter() in java?

getParameter() returns http request parameters. Those passed from ...READ MORE

answered Aug 28, 2019 in Java by Sirajul
• 59,230 points
22,393 views
0 votes
2 answers

What is the difference between Type List and type ArrayList in Java

By List, you actually tell, that your object ...READ MORE

answered Aug 28, 2019 in Java by Sirajul
• 59,230 points
2,487 views
0 votes
1 answer

What is the difference between getPath(), getAbsolutePath() and getCanonicalPath() in Java?

getPath() - returns a String which denotes the ...READ MORE

answered Jul 26, 2018 in Java by Mrunal
• 680 points
1,867 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 80,951 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
8,263 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
17,355 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points

edited Aug 4, 2023 by Khan Sarfaraz 4,769 views
0 votes
1 answer

What is an Operand Stack in Java?

The basic utility of Operand Stack are ...READ MORE

answered Mar 7, 2019 in Java by Priyaj
• 58,100 points
1,810 views
0 votes
1 answer

How is inheritance in C++ different than that in Java?

The purpose of inheritance is same for ...READ MORE

answered Feb 6, 2019 in Java by Priyaj
• 58,100 points
933 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP