I'm reading SCJP by Kathy Sierra and Bert Bates and it says on pg. 21 that "The public modifier is required if you want the interface to have public rather than default access". Is this true? If yes, then the interface methods (which are always public) only accessible if the interface is in the same package of the implementing class...? Since that is the meaning of the default access modifier...I'm a bit confused on this.
Is it true that if you don't specify an access modifier for an interface, that interface will have default access
6.2k Views Asked by user1142130 At
2
There are 2 best solutions below
0
AudioBubble
On
Here the interface itself is package protected but the methods are always public by default
interface Foo
{
void bar(); // this is always public and nothing else
}
Here the interface is public as well as the methods
public interface Foo
{
void bar(); // this is always public and nothing else
}
you can declare public void bar(); or void bar(); they mean the same thing, personally, I always put the public because explicit is always better than implicit
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in INTERFACE
- C++ inheritance, interfaces
- Multiple service contract inter-commnication
- Passing Variables from VBA to R-Script
- Static interface equivalent C#
- What text (in English) should I use when asking the user to overwrite a document?
- Java generic class that contains an instance of implementation of generic interface
- HuggableInterface in PHP and PSR-8
- How do I define constants that must be overridden inside an interface?
- Symfony : is there a best practice about the directories' name including traits and interfaces?
- How to design structure with modifiable fields?
- Why introducing Autocloseable instead of extending the possible exceptions in Closeable
- CI accessing property on interface
- C# list of "Type" that implements specific interface
- ResultTransformer interface in java
- How can I guarantee that a class that implements an interface also extends a class?
Related Questions in METHODS
- PHPunit call magic methods
- Needing a private and public method for the same recursive function
- #warning this method is no longer used (Objective-C)
- Issue with calling a method and updating graphics
- Shoppe gem each method on product categories
- Using NON static class Methods Without reference
- Java: Shuffle a Deck of 32 cards?
- Does .join method change the array into string in Javascript?
- Simplify code with sending Methods as Variable
- Programmatic Access to Apple Watch Crown
- How to change URL form with GET method?
- Why is this method called instead of the other?
- Inheritance Hidden Method java
- Java: How to create simple method
- Are methods copied when objects are created?
Related Questions in ABSTRACT
- Implementing Iterator for abstractCollection
- Trouble creating pointer to abstract class
- Java: Abstract classes methods and interface
- Reuse conditional statements in sub-classes.
- Cannot instantiate abstract class: Why is the template parameter (reference) causing this?
- implementing abstract methods in matlab
- How to use entity framework with business objects
- static method declaration in abstract class
- Type error when when trying to override a generic function in a concrete implementation of an abstract class
- Symbol not found on Comparer<T>
- Extract abstract / full text from scientific literature given DOI or Title
- Real time use of abstract, sealed and static class
- How to instantiate an abstract class in Java?
- Force SubClasses to @Override method from SuperClass. Method in SuperClass must have body
- How do I know what class called the abstract method?
Related Questions in SCJP
- Confusion regarding hashset, hashmap, hashcode, equals
- char and byte with final access modifier - java
- Is id = 1 - id atomic?
- Methods that don't change a variable's value need to be synchronized if they accessed the variable
- x = x++ doesn't increment because the ++ is applied after the assignment?
- Inconsistent behaviour of primitive integer types in Java
- what is better ... OCJA7 then OCJP7 or SCJP6 then upgrade to OCJP7?
- If I have several Strings formatted differently do I need a separate instance of DateFormat to parse each String?
- Why can't I handle Exception e with try / catch clause?
- Why do static and instance init blocks in Enums behave differently from those in Classes
- two threads one synchronize method scjp
- How can I make a public static unsynchronized getInstance() method return multiple instances of a private static reference variable to an object?
- Confusion with StringBuilder in java
- Enthuware Sample - hashCode and equals
- Confusing while block
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Yes that is true. Java types/fields/methods (in class) have package-level access if access modifier is not specified. Members defined in inteface type are public by-default.
Read tutorial - Controlling Access to Members of a Class.