Example6:- A.java
interface A
{
void disp();
}
Output:-
C:\JAVATECH>javac A.java
C:\JAVATECH>javap A
Compiled
from "A.java"
interface
A {
public abstract void disp();
}
Explanation:
-
Interface contains only abstract methods only and all interface methods are by
default public and abstract.
Example7:- A.java
interface A
{
public abstract void disp();
}
Output:-
C:\JAVATECH>javac A.java
C:\JAVATECH>javap A
Compiled
from "A.java"
interface
A {
public abstract void disp();
}
Example8:- A.java
interface A
{
abstract public void disp();
}
Output:-
C:\JAVATECH>javac A.java
C:\JAVATECH>javap A
Compiled
from "A.java"
interface
A {
public abstract void disp();
}
Example9:- A.java
interface A
{
void disp();
int set();
}
Output:-
C:\JAVATECH>javac A.java
C:\JAVATECH>javap A
Compiled
from "A.java"
interface
A {
public abstract void disp();
public abstract int set();
}
Example10:- A.java
interface A
{
void disp()
{
System.out.println("This is concrete
method");
}
}
Output:-
C:\JAVATECH>javac A.java
A.java:4:
error: interface abstract methods cannot have body
{
^
1
error
Explanation:
- Interface
contains only abstract methods, cannot contains concrete methods.
Comments
Post a Comment