Java Programming - Declarations and Access Control - Discussion

Discussion Forum : Declarations and Access Control - General Questions (Q.No. 18)
18.
Which is a valid declaration within an interface?
public static short stop = 23;
protected short stop = 23;
transient short stop = 23;
final void madness(short stop);
Answer: Option
Explanation:

(A) is valid interface declarations.

(B) and (C) are incorrect because interface variables cannot be either protected or transient. (D) is incorrect because interface methods cannot be final or static.

Discussion:
11 comments Page 1 of 2.

Bharath said:   1 decade ago
public static short stop=23; is given as correct answer but how come its possible, interface does not accept static modifiers?

Hariom singh said:   1 decade ago
What is the working of join method in threading ?

Pawan patidar said:   1 decade ago
public static short stop=23; is given as correct answer but how come its possible, interface does not accept static modifiers?

Prabhat Kumar said:   1 decade ago
Option A is also wrong, because static methods r not allowed in interfaces.

Google said:   1 decade ago
Public static short stop=23; is given as correct answer but how come its possible, interface does not accept static modifier?

Mitesh Jain(Ujjain) said:   1 decade ago
The answer(A) is right, because data member of interface can be static, final and public. Yes, Interface and classes can't be static. And interface's methods also can't be static. But data member is possible.

Gowtham said:   1 decade ago
Yeah static methods are not allowed then how?
(1)

Nirali khunt said:   1 decade ago
Interface can not initialize the variable so it is not possible.

Vishnu kumar ravula said:   10 years ago
How can you access a static variable in interface using the its name without reference ?

Vijay said:   8 years ago
Interface by default all the variables are " PUBLIC STATIC FINAL " and all the methods are " PUBLIC and ABSTRACT ".

I hope it is clear now.


Post your comments here:

Your comments will be displayed after verification.