Set - 7

Question 21 :

Can an Interface have an inner class?

Answer :

Yes

public interface abc {
 static int i=0;
 void dd();
 class a1 {
  a1() {
   int j;
   System.out.println("in interfia");
  };
  public static void main(String a1[]) {
   System.out.println("in interfia");
  }
 }
}


Question 22 :

Can we define private and protected modifiers for variables in interfaces?

Answer :

Yes.


Question 23 :

What is Externalizable?

Answer :

Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format.
It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)


Question 24 :

What modifiers are allowed for methods in an Interface?

Answer :

Only public and abstract modifiers are allowed for methods in interfaces.


Question 25 :

What is a local, member and a class variable?

Answer :

Variables declared within a method are "local" variables.
Variables declared within the class i.e not within any methods are "member" variables (global variables).
Variables declared within the class i.e not within any methods and are defined as "static" are class variables