java chapter11 practice question on abstruct class and interfaces
/*
Chapter 11 - Practise Set
1... Create an abstract class Pen with methods
Write () and refill 1) as abstract methods
2... Use the Pen Class from Q1 to create a
Concrete class fountain Pen with additional method change Nibl)
3...Create a class Monkey with jump () and bitel) methods. Create a class Human which inherits
this Monkey class and implements Basic Animalinterface with eati) and sleep methods.
4.... Greate a class Telephone with ring() liftus
and disconnect ( methods as abstract methods Create another
class Smart Telephone and demonstratepolymorphism
5.....Demonstrate polymorphism Msing monkey class from Quess 3.
6.......Create an Interface TV Remote and use it to inheritanother Interface Smart Tv Remote
7...... Create a Class Tv which implements Tv Remote interface qsn 6
*/
package com.company;
//programe 1
abstract class Pen{
abstract void Write();
abstract void Refill();
}
//programe 2
class FountainPen extends Pen {
void Write() {
System.out.println("write");
}
void Refill() {
System.out.println("refill");
}
void Changenib() {
System.out.println("changing nib");
}
}
//program3
class monkey{
void jump(){
System.out.println("jumping.....");
}
void bite(){
System.out.println("biting....");
}
}
interface basicanimal{
void eat();
void sleep();
}
class human extends monkey implements basicanimal{
void speak(){
System.out.println("hello sir hello sir...");
}
@Override
public void eat(){
System.out.println("eating......");
}
public void sleep(){
System.out.println("........sleep.......");
}
}
public class cwh_chapter11_practice_set_abstructclass_interface {
public static void main(String[] args) {
//1+2
FountainPen pen=new FountainPen();
pen.Changenib();
//3
human harry =new human();
harry.sleep();
//5
monkey m1= new human();
//m1.speak();
m1.jump();
m1.bite();
basicanimal lavish=new human();
//lavish.speak();
lavish.eat();
lavish.sleep();
}
}
Comments
Post a Comment