java(polymorphisome)
package com.company;
interface Mycamera{
void TakeSnap();
void recordvideo();
//keu use korte prbe na for private,but fayeda hoy
//jokhn default method onek boro hoy tokhn private method e rekhe ,private method use korte prbo
private void great(){
System.out.println("good night........");
}
//default method add kora jay jokhn new inrerface er intilize er sathei method declare korar jonno,
//jodi pore method declas kora hoy tale r default kaj korbe na
default void record4kvideo(){
great();
System.out.println("recording in 4k......");
}
}
interface Mywifi{
String[] getNetworks();
void connecttonetwork(String network);
}
class Cellphone{
void callnumber(int phonenumber){
System.out.println("calling..."+phonenumber);
}
void pickcall(){
System.out.println("connecting....");
}
}
class MYsmartphone extends Cellphone implements Mywifi,Mycamera {
public void TakeSnap() {
System.out.println("taking snap");
}
//public void record4kvideo() {
// System.out.println("taking snap and hd... record video. in 4k.....");
//}
public void recordvideo() {
System.out.println("taking video");
}
public String[] getNetworks() {
System.out.println("getting list of network");
String[] networklist = {"voda", "idea", "jio", "airtel"};
return networklist;
}
public void connecttonetwork(String network) {
System.out.println("connecting to" +network);
}
public void samplemethod(){
System.out.println("method");
}
}
public class cwh_chapter11_polymorphisome_in_interface {
public static void main(String[] args) {
Mycamera cam=new MYsmartphone();
//cam.getNetworks();-----------not allowed for goods
//cam.getNetworks();
cam.record4kvideo();
//cam.samplemethod();-----------not allowed
MYsmartphone c2= new MYsmartphone();
c2.samplemethod();
c2.recordvideo();
c2.getNetworks();
c2.callnumber(98);
}
}
Comments
Post a Comment