Starting from:

$24.99

OOPs Day 2: Assignment - Concepts Solution

Problem statement - Create an abstract class - Animal having the following properties and getter/setter methods and other behavior methods..

name : String no-args constructor constructor initializing all fields getter/setter methods makeNoise() - abstract method
sleep() - print any statement using println() method in this method i.e. Animal is sleeping eat() - abstract method
Now create two classes extending Animal as base class as following
Dog class
breed : String no-args constructor constructor initializing all fields of this class constructor initializing field of this + name of super class getter/setter methods
Override makeNoise() and eat() methods define new method - play() : void (it should print any statement i.e. - Dog is playing)
Day 2: Assignment - OOPs Concepts 1
Cat class
nickName: String no-args constructor constructor initializing all fields of this class constructor initializing field of this + name of super class getter/setter methods
Override makeNoise() and eat() methods define new method - jump() : void (it should print any statement i.e. - Cat is jumping)
Main class
should have the main() method create objects of Cat and Dog using superclass reference variable
i.e. Animal animal = new Cat(); try to call all the methods on the object reference variable and observe the output
NOTE: The objective of the above problem statement is to get understanding on the following concepts
Objects and relationship (inheritance)
Role of constructors in inheritance
Concepts of overriding and overloading methods use of super keyword to initialize objects properly from subclass instance
Type Casting supertype into subtype
Understanding polymorphism, encapsulation, inheritance
Day 2: Assignment - OOPs Concepts 2

More products