Java Programming - Declarations and Access Control
Why Java Programming Declarations and Access Control?
In this section you can learn and practice Java Programming Questions based on "Declarations and Access Control" and improve your skills in order to face the interview, competitive examination and various entrance test (CAT, GATE, GRE, MAT, Bank Exam, Railway Exam etc.) with full confidence.
Where can I get Java Programming Declarations and Access Control questions and answers with explanation?
IndiaBIX provides you lots of fully solved Java Programming (Declarations and Access Control) questions and answers with Explanation. Solved examples with detailed answer description, explanation are given and it would be easy to understand. All students, freshers can download Java Programming Declarations and Access Control quiz questions with answers as PDF files and eBooks.
Where can I get Java Programming Declarations and Access Control Interview Questions and Answers (objective type, multiple choice)?
Here you can find objective type Java Programming Declarations and Access Control questions and answers for interview and entrance examination. Multiple choice and true or false type questions are also provided.
How to solve Java Programming Declarations and Access Control problems?
You can easily solve all kind of Java Programming questions based on Declarations and Access Control by practicing the objective type exercises given below, also get shortcut methods to solve Java Programming Declarations and Access Control problems.
Access modifiers dictate which classes, not which instances, may access features.
Methods and variables are collectively known as members. Method and variable members are given access control in exactly the same way.
private makes a member accessible only from within its own class
protected makes a member accessible only to classes in the same package or subclass of the class
default access is very similar to protected (make sure you spot the difference) default access makes a member accessible only to classes in the same package.
public means that all other classes regardless of the package that they belong to, can access the member (assuming the class itself is visible)
final makes it impossible to extend a class, when applied to a method it prevents a method from being overridden in a subclass, when applied to a variable it makes it impossible to reinitialise a variable once it has been initialised
abstract declares a method that has not been implemented.
transient indicates that a variable is not part of the persistent state of an object.
volatile indicates that a thread must reconcile its working copy of the field with the master copy every time it accesses the variable.
After examining the above it should be obvious that the access modifier that provides the most restrictions for methods to be accessed from the subclasses of the class from another package is C - protected. A is also a contender but C is more restrictive, B would be the answer if the constraint was the "same package" instead of "any package" in other words the subclasses clause in the question eliminates default.
(3) is correct because an abstract class doesn't have to implement any or all of its interface's methods. (4) is correct because the method is correctly implemented ((7 > 4) is a boolean).
(1) is incorrect because interfaces don't implement anything. (2) is incorrect because classes don't extend interfaces. (5) is incorrect because interface methods are implicitly public, so the methods being implemented must be public.