Professional Documents
Culture Documents
Department CSE
Marker interfaces:
It is the empty interface. Marker interface does not have any
method in it.
There are 3 types of Marker interfaces:
1. Serializable interface: It is used to convert object into byte
stream.
2. Cloneable interface: It is used to clone the object.
3. Remote interface: It allows an object residing in one system
to access or invoke an object running on another system.
Code:
import java.util.*;
import java.io.*;
interface P {}
class basic implements P
{
void show() {System.out.println("hello");}
Indian Institute of Information Technology, Pune
}
public class marker_interface_1
{
public static void main(String args[])
{
basic x=new basic();
if(x instanceof P) x.show();
else System.out.println("NO\n");
}
}
Function interface:
It is the interface which has only one abstract method. Functional
interface is also called as Single abstract method(SAM) interface.
Runnable , Comparable are the example of Functional interface.
Code:
import java.io.*;
import java.util.*;
@FunctionalInterface
interface Q { void show();}
public class function_interface_1
{
public static void main(String args[])
{
Q x=new Q()
{
public void show()
{
System.out.println("hello i am single function");
}
};
x.show();
}
}
Normal interfaces:
It is the interface which has more than one abstract method.
Code:
import java.util.*;
import java.io.*;
Indian Institute of Information Technology, Pune
interface R
{
void show();
void colur(String s);
}
public class normal_interface_1 implements R
{
public static void main(String args[])
{
normal_interface_1 x=new normal_interface_1();
x.show();
x.colur("red");
}
@Override
public void show()
{
System.out.println("hi i am normal interface");
}
@Override
public void colur(String s)
{
System.out.println("i like "+s);
}
}
Private:
In this variable & class are declared private, such that they can’t be
access outside the class. similarly packages with private data
members also can’t called in different package
Example code:
Indian Institute of Information Technology, Pune
Protected:
In this variable & class are protected, such that they can be access
within the same package & the following sub-classes
Example code:
Public :
In this variable & class are public, such that they can be access from
anywhere within the package and outside the package.
Example code:
Default:
In this variable & class are not given any access modifiers, such that
they can be access from only same package .like protected but not
from sub-classes
Example code:
int abc;
}
If y>0
This are some function that we can use while performing file handling
Q5 Distinguish between
Indian Institute of Information Technology, Pune