Example1:- A.java
interface A
{
int a;
}
Output:-
C:\JAVATECH>javac A.java
A.java:3:
error: = expected
int
a;
^
1
error
Explanation:
- Interface
variable must initialize at declaration time because by default interface
variables are public static and final.
Example2:- A.java
interface A
{
int a=100;
}
Output:-
C:\JAVATECH>javac A.java
C:\JAVATECH>javap A
Compiled
from "A.java"
interface
A {
public static final int a;
}
Explanation: -
by default interface variables are public static and final.
Example3:- A.java
interface A
{
public static final int a=100;
}
Output:-
C:\JAVATECH>javac A.java
C:\JAVATECH>javap A
Compiled
from "A.java"
interface
A {
public static final int a;
}
Example4:- A.java
interface A
{
static public final int a=100;
}
Output:-
C:\JAVATECH>javac A.java
C:\JAVATECH>javap A
Compiled
from "A.java"
interface
A {
public static final int a;
}
Explanation:
- Here
public, static and final all are modifiers, and order of modifiers can
interchange.
Example5:- A.java
interface A
{
final static
public int a=100;
}
Output:-
C:\JAVATECH>javac A.java
C:\JAVATECH>javap A
Compiled
from "A.java"
interface
A {
public static final int a;
}
Comments
Post a Comment