Default Methods In Java
package com.company;
interface Camera{
void takeSnap();
void recordVideo();
default void record4KVideo(){
// We can override this default method in the class but then this method will not work
// instead the method in class will work.
System.out.println("Recording In 4k ...");
}
}
interface Wifi{
String [] getNetwork();
void connectToNetwork(String network);
}
class CellPhone{
void callNumber(int phoneNumber){
System.out.println("Calling"+ phoneNumber);
}
void pickCall(){
System.out.println("Connecting ...");
}
}
class SmartPhone extends CellPhone implements Wifi, Camera{
public void takeSnap(){
System.out.println("Taking Snap");
}
public void recordVideo(){
System.out.println("Taking Videp");
}
public String[] getNetwork(){
System.out.println("Getting the list of networks ...");
String[] networkList = {"Digisol", "UCN_Dr_Sonone"};
return networkList;
}
public void connectToNetwork(String network){
System.out.println("Connecting to "+ network + " ...");
System.out.println("Connected");
}
}
public class tuts {
public static void main(String[] args) {
SmartPhone sp = new SmartPhone();
String[] ar = sp.getNetwork();
for (String item: ar) {
System.out.println(item);
}
sp.connectToNetwork("UCN_Dr_Sonone");
sp.record4KVideo();
}
}
Comments
Post a Comment