Can we define a variable with the access modifier private
in an interface?
Answers were Sorted based on User's Feedback
Answer / bindu sharma
No,In an interface we cannot declare any variable either it
is public or private or any other access modifiers.
| Is This Answer Correct ? | 29 Yes | 4 No |
Answer / rajat
No you cannot.
1. Because an interface cannot contain fields.
2. For methods also, you cannot give an access modifier
(public / private). By default, the methods will be public
| Is This Answer Correct ? | 17 Yes | 0 No |
Answer / arpita malviya
Interface cannot contains fields , irrespective of its
access modifier.
| Is This Answer Correct ? | 13 Yes | 0 No |
Answer / murugavel
No..Not possible. Interface is only having methods. We can't
declare variables on it. The methods also be a public.
| Is This Answer Correct ? | 4 Yes | 2 No |
Answer / hp
Yes we can declare variables in interafces
sample:
public interface nexusConstants {
// servlet names
public final String CSR_QUERY_SERVLET = "/qryCSS";
public final String MY_BILL_QUERY_SERVLET = "/qryMyBill";
public final String MY_HOME_QUERY_SERVLET = "/qryMyHome";
public final String TRY_BILL_QUERY_SERVLET = "/qryTryBill";
public final String CSR_XFER_SERVLET = "xferCSS"; }
This can be used by any class which require th values.
I have a live application which uses the interface variables.
| Is This Answer Correct ? | 0 Yes | 0 No |
write code for Factorial?
Explain ACID rule of thumb for transactions.
What is typeof c#?
How do you generate documentation from the C# file commented properly with a command-line compiler?
How many bytes is an int?
Why singleton class is sealed in c#?
How do I start a program in c#?
How do I create a .exe file?
Can we declare private class in c#?
Wht executescaler method is used?
What are object pooling and connection pooling and difference between them?
What are the properties in c#?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)