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
18,934 views

4 answers to this question.

0 votes
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
• 57,640 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.
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 27, 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 27, 2019 by Pratosh kumar

Related Questions In Java

0 votes
2 answers

What is the difference between Set and List in java?

LIST SET Duplicates YES NO Order Ordered Depends on Implementation Positional Access YES NO List is an ordered sequence ...READ MORE

answered Aug 14, 2019 in Java by Sirajul
• 57,870 points
832 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
• 57,870 points
6,502 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
• 57,870 points
375 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 25, 2018 in Java by Mrunal
• 680 points
704 views
+5 votes
3 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 6, 2018 by Omkar 29,697 views
0 votes
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,510 points
4,309 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,510 points
10,184 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,510 points
1,824 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
• 57,640 points
349 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
• 57,640 points
114 views