Can we define a variable with the access modifier private
in an interface?

Answers were Sorted based on User's Feedback



Can we define a variable with the access modifier private in an interface?..

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

Can we define a variable with the access modifier private in an interface?..

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

Can we define a variable with the access modifier private in an interface?..

Answer / arpita malviya

Interface cannot contains fields , irrespective of its
access modifier.

Is This Answer Correct ?    13 Yes 0 No

Can we define a variable with the access modifier private in an interface?..

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

Can we define a variable with the access modifier private in an interface?..

Answer / vikas

no not at all

Is This Answer Correct ?    1 Yes 0 No

Can we define a variable with the access modifier private in an interface?..

Answer / vimal

Yes

Is This Answer Correct ?    2 Yes 2 No

Can we define a variable with the access modifier private in an interface?..

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

Post New Answer

More C Sharp Interview Questions

What are properties in c#. Explain with an example?

0 Answers  


If I have more than one version of one assemblies, then how'll I use old version (how/where to specify version number?)in my application?

0 Answers  


How many static constructors are allowed in a class?

0 Answers  


What is the default value of guid in c#?

0 Answers  


How many types of interface are there in c#?

0 Answers  






What is trim in c#?

0 Answers  


I have a class declared as below public class a { public void add() {} } What is the diference between a a1 =new a; and simply a a1;

3 Answers  


What's difference between constants and static readonly?

0 Answers   Wipro,


In a site to turn off cookies for one page which method is followed?

0 Answers   Siebel,


What is difference between throw and throws in c#?

0 Answers  


List the two important objects of ado.net and also list the namespaces that are commonly used in ado.net to aid in connection to a database.

0 Answers  


Explain use of abstract and sealed classes in c#?

0 Answers  


Categories