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?
  1. protected abstract void m1();
  2. static final void m1(){}
  3. synchronized public final void m1() {}
  4. private native void m1();
1 and 3
2 and 4
1 only
All of them are legal declarations.
Answer: Option
Explanation:

All the given statements are legal declarations.

Discussion:
14 comments Page 1 of 2.

Rahul said:   7 years ago
Public, static, final are all constant then how can we use final with static?
(2)

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)

Sainath said:   1 decade ago
Can you explain it in detail?

Vinu said:   1 decade ago
Can any one explain ?

Sush said:   1 decade ago
Please anyone explain it?

Rocks said:   1 decade ago
What is the working of synchronize and native?

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.

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

Chandra Bhushan said:   1 decade ago
But as I can see the question is asked for declaration only and not the definition of function.

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.


Post your comments here:

Your comments will be displayed after verification.