Posts

Ch11_59_PolymorphismInInterfaces

  package com.company ; interface MyWifi2 { public String [] networkList (); } interface MyCamera2 { public void takeSnap (); public void recordVideo (); default public void filter () { System . out . println ( "New filters are : Doggy, Sunrise, light Hair" ); } } class MyCellphone2 { public void makeCall ( int phoneNumber1 , int phoneNumber2 ) { System . out . println ( "Calling ..." + phoneNumber1 + "" + phoneNumber2 ); } } class MySmartPhone3 extends MyCellphone2 implements MyWifi2 , MyCamera2 { public String [] networkList () { System . out . println ( "Available networks are ..." ); String [] str = { "Harry" , "Tenda343041" , "Airtel001" }; return str ; } public void takeSnap () { System . out . println ( "Taking snap..." ); } public void recordVideo () { System . out . println ( "Recording vide...

Ch11_58_InheritanceInInterface

  package com.company ; interface sampleInterface { public void meth1 (); public void meth2 (); } interface childSampleInterface extends sampleInterface { // Inheritance in interface public void meth3 (); public void meth4 (); } class sampleClass implements childSampleInterface { @Override public void meth3 () { System . out . println ( "Meth 3" ); } @Override public void meth4 () { System . out . println ( "Meth 4" ); } public void meth1 () { System . out . println ( "Meth 1" ); } public void meth2 () { System . out . println ( "Meth 2" ); } } public class Ch11_58_InheritanceInInterface { public static void main ( String [] args ) { sampleClass cl = new sampleClass (); cl . meth1 (); cl . meth2 (); cl . meth3 (); cl . meth4 (); } }

Ch11_57_DefaultMethods

  package com.company ; interface wifi { public String [] networkList (); } interface camera { public void takeSnap (); public void recordVideo (); default public void filter () { System . out . println ( "New filters are : Doggy, Sunrise, light Hair" ); } } class cellPhone { public void makeCall ( int phoneNumber1 , int phoneNumber2 ) { System . out . println ( "Calling ..." + phoneNumber1 + "" + phoneNumber2 ); } } class MySmartPhone extends MyCellphone2 implements MyWifi2 , MyCamera2 { public String [] networkList () { System . out . println ( "Available networks are ..." ); String [] str = { "Harry" , "Tenda343041" , "Airtel001" }; return str ; } public void takeSnap () { System . out . println ( "Taking snap..." ); } public void recordVideo () { System . out . println ( "Recording video.......

Ch11_55_MultipleInterfaces

  package com.company ; interface bicycle1 { public int applyBreak ( int decrement ); public int speedUp ( int increment ); public void displaySpeed ( int increment , int decrement ); } interface GearCycle { public String shiftGear ( int speed ); } class AvonCycle1 implements bicycle1 , GearCycle { int speed ; public AvonCycle1 ( int speed ) { this . speed = speed ; } public int getSpeed () { return speed ; } public String shiftGear ( int speed ) { if ( speed > 0 && speed < 5 ) { return "1st" ; } else if ( speed >= 5 && speed < 10 ) { return "2nd" ; } else if ( speed >= 10 && speed < 15 ) { return "3rd" ; } else if ( speed >= 15 && speed < 20 ) { return "4th" ; } else if ( speed >= 20 ) { return "5th" ; } else { ...

Ch11_54_IntroductionToInterfaces

  package com.company ; interface bicycle { public int applyBreak ( int decrement ); public int speedUp ( int increment ); public void displaySpeed ( int increment , int decrement ); } class AvonCycle implements bicycle { int speed = 7 ; public int getSpeed () { return speed ; } public int applyBreak ( int decrement ) { speed = speed - decrement ; return speed ; } public int speedUp ( int increment ) { speed = speed + increment ; return speed ; } public void displaySpeed ( int increment , int decrement ) { System . out . println ( "Initial speed of bicycle is : " + this . getSpeed () + "km/hr" ); System . out . println ( "The speed of bicycle after applying break is : " + this . applyBreak ( decrement ) + "km/hr" ); System . out . println ( "The speed of bicycle after speed up is : " + this . speedUp ( increment ) + "km/hr...

Ch11_53_AbstractClassAndMethods

  package com.company ; abstract class parent { public int age ; public void age ( int age ) { this . age = age ; System . out . println ( "Parent age is : " + age ); } public void intro () { System . out . println ( "I am parent" ); } abstract public void greet (); abstract public void greet2 (); } class child extends parent { int age = 12 ; public void age () { System . out . println ( "I am 17 years old." ); } @Override public void greet () { System . out . println ( "Good Afternoon." ); } @Override public void greet2 () { System . out . println ( "Good evening." ); } } abstract class child2 extends parent { @Override public void intro () { System . out . println ( "I am child 2." ); } @Override public void greet2 () { System . out . println ( "Good evening." ); } ...

PS_Ch10_Q5

  package com.company.Ch10_52_PracticeSet ; class base_ch10 { public base_ch10 () { System . out . println ( "Base class constructor." ); } } class derived1_ch10 extends base_ch10 { public derived1_ch10 () { System . out . println ( "Derived1 class constructor." ); } } class derived2_ch10 extends derived1_ch10 { public derived2_ch10 () { System . out . println ( "Derived2 class constructor." ); } } public class PS_Ch10_Q5 { public static void main ( String [] args ) { derived2_ch10 obj = new derived2_ch10 (); } }