Java Programming - Declarations and Access Control - Discussion
Discussion Forum : Declarations and Access Control - General Questions (Q.No. 7)
7.
Which of the following is/are legal method declarations?
- protected abstract void m1();
- static final void m1(){}
- synchronized public final void m1() {}
- private native void m1();
Answer: Option
Explanation:
All the given statements are legal declarations.
Discussion:
14 comments Page 1 of 2.
Venkat said:
1 decade ago
1. protected abstract void m1();
Is correct because abstract method may be implemented in subclass and protected allows it to do so.
2. static final void m1(){}
Is also correct because final does not allow method to be changed and static does not user to another method with same name.
3. synchronized public final void m1() {}
It allow only one instance of method to be executed at a time.
4. private native void m1();
It allows method written in another programming language to be executed in java
Is correct because abstract method may be implemented in subclass and protected allows it to do so.
2. static final void m1(){}
Is also correct because final does not allow method to be changed and static does not user to another method with same name.
3. synchronized public final void m1() {}
It allow only one instance of method to be executed at a time.
4. private native void m1();
It allows method written in another programming language to be executed in java
Adrian said:
1 decade ago
Synchronize and native works because synch blocks the execution of other methods on the same class (for the duration of the method). Maybe the native method wants to modify a shared resource.
Limia said:
1 decade ago
Shouldn't access specifiers like public, private and protected be the first words in a declaration statement? Please correct me if I'm wrong, I read this somewhere.
Jatinder Verma said:
10 years ago
There are only two method declarations:
1. Protected abstract void m1();
2. Private native void m1();
Except these all others are methods with definition.
1. Protected abstract void m1();
2. Private native void m1();
Except these all others are methods with definition.
(1)
Amaziane said:
1 decade ago
I have some doubt that the declaration protected abstract void m1();
Compile, at least in my workspace with jdk7.
Compile, at least in my workspace with jdk7.
Chandra Bhushan said:
1 decade ago
But as I can see the question is asked for declaration only and not the definition of function.
Rahul said:
7 years ago
Public, static, final are all constant then how can we use final with static?
(2)
Manohar said:
1 decade ago
static final void m1(){}
Can anyone explain it clearly?
Can anyone explain it clearly?
Rocks said:
1 decade ago
What is the working of synchronize and native?
Kaustubh Kaley said:
1 decade ago
Why are {} specified in the declaration?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers