Republic of the Philippines
Department of Education
Region I
PANGASINAN SCHOOLS DIVISION OFFICE II
BENIGNO V. ALDANA NATIONAL HIGH SCHOOL
CABLONG, POZORRUBIO, PANGASINAN
Computer Programming 1
NAME: ________________________________________
Scores:
STRAND: ______________________________________ Date: ________
1. Write a Java program to create an abstract class Animal with abstract methods eat() and
sleep(). Create subclasses Lion, Tiger, and Deer that extend the Animal class and implement
the eat() and sleep() methods differently based on their specific behavior.
- this program, the Animal class is an abstract class that defines the abstract methods eat()
and sleep(). The Lion, Tiger, and Deer classes extend the Animal class and provide their
own implementations for the eat() and sleep() methods based on their specific behavior.
The Main class demonstrates the usage of these classes by creating objects of each subclass
and invoking the eat() and sleep() methods accordingly.
Output:
Lion eats meat.
Lion sleeps on grassland.
Tiger eats meat and occasionally hunts in water.
Tiger sleeps in a hidden spot.
Deer grazes on grass and leaves.
Deer sleeps in open fields.
2. Write a Java program to create a method that takes an integer as a parameter and throws an
exception if the number is odd.
Output:
18 is even.
Error: 7 is odd.
3.
Prepared by: Approved by: Noted by:
RAQUEL S. QUINIT ROGER Z. ESTABILLO JR. PhD EDDIE M. RAGUINDIN EdD
Teacher II Assistant School Principal IV EPS – Science / OIC Principal IV
_________________________________________________________
SIGNATURE OVER PRINTED NAME OF PARENTS/GAURDIAN
4.