Posts

Showing posts from 2021

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&qu

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 (); } }

PS_Ch10_Q2andQ4

  package com.company.Ch10_52_PracticeSet ; class rectangle { int length ; int breadth ; public int getLength () { return length ; } public void setLength ( int length ) { this . length = length ; } public int getBreadth () { return breadth ; } public void setBreadth ( int breadth ) { this . breadth = breadth ; } public int area () { return this . length * this . breadth ; } public void display () { System . out . format ( "The area of rectangle having length %d and breadth %d is %d. \n " , this . getLength (), this . getBreadth (), this . area ()); } } class cuboid extends rectangle { int height ; public int getHeight () { return height ; } public void setHeight ( int height ) { this . height = height ; } public int volume () { return this . length * this . breadth * this . height ; } public void display () {

PS_Ch10_Q1andQ3

package com.company.Ch10_52_PracticeSet ; class circle { int r ; public circle ( int r ) { this . r = r ; } public int getR () { return r ; } public double area () { // Question 3 return Math . PI * this . r * this . r ; } public void display () { System . out . format ( "The area of circle having radius %d is : %.2f. \n " , this . getR (), this . area ()); } } class cylinder_Q1 extends circle { int h ; public cylinder_Q1 ( int r , int h ) { super ( r ); this . h = h ; } public int getH () { return h ; } public double volume () { // Question 3 return Math . PI * this . r * this . r * this . h ; } public void display () { System . out . format ( "The volume of cylinder having radius %d and height %d is %.2f. \n " , this . getR (), this . getH (), this . volume ()); } } public class PS_Ch10_Q1andQ3 { public static void mai

Ch10_51_Ex4_Library

  package com.company ; import java.util.Scanner ; class library { String [] availableBooks = new String [ 100 ]; int [] bookCode = new int [ 100 ]; int noOfBooks = 0 ; String [] issuedBooks = new String [ 100 ]; public void addBooks ( int n ) { Scanner scan = new Scanner ( System . in ); for ( int i = noOfBooks ; i < n ; i ++) { System . out . print ( "Enter the name of book : " ); availableBooks [ i ] = scan . next (); System . out . print ( "Enter the code no. of the book \" " + availableBooks [ i ] + " \" : " ); bookCode [ i ] = scan . nextInt (); noOfBooks ++; } } public void returnBook () { System . out . print ( "How many books you want to return : " ); Scanner scan = new Scanner ( System . in ); int n = scan . nextInt (); addBooks ( n + noOfBooks ); } public void showAvailab