Las Ict7 Java Q3 Las 4
Las Ict7 Java Q3 Las 4
QUARTER 3 WEEK 4
Learning Activity Sheet
Quarter 3 – Activity Sheet 4: Creating Classes
Unang Edisyon, 2023
Republic Act 8293, section 176 states that: No copyright shall subsist in any work of the
Government of the Philippines. However, prior approval of the government agency or
office wherein the work is created shall be necessary for exploitation of such work for
profit. Such agency or office may, among other things, impose as a condition the payment
of royalties.
Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand names,
trademarks, etc.) included in this module are owned by their respective copyright holders.
Every effort has been exerted to locate and seek permission to use these materials from
their respective copyright owners. The publisher and authors do not represent nor claim
ownership over them.
This Learning Activity Module (LAS) was designed and written with you in mind. It is
here to help you master Java Technology and the Java Programming Language. The
scope of this module permits it to be used in many different learning situations. The
language used recognizes the diverse vocabulary level of students. The lessons are
arranged to follow the standard sequence of the course. But the order in which you
read them can be changed to correspond with the textbook you are now using.
The LAS is divided into one (1) learning outcome, specifically:
In this Learning Activity Sheet, you will study about Java technology and
Java programming.
1. Study the lessons and answer religiously the activities. These will guide you on
what you will learn at the end of this Learning Activity Sheet.
Activity 1:
Directions: Look at the sample class diagrams below. Provide the attributes
asked of the given class by providing details of each property in the box.
TV
Brand: ________________
Color:_________________
Size:__________________
Can Turn On (Yes/No):_________
Can Change Volume (Yes/No):________
Can Change Channel (Yes/No):_________
School
Name: __________________________________
Elementary or High School:______________
Estimated Population:___________________
Accepts Transferees (Yes/No):_________
Suspends classes (Yes/No):_________
Has Flag Ceremony (Yes/No):__________
Class
Example:
Sample Code:
What is a method?
Creating a Method
Method Calling
Passing Parameters
When you create a new instance (a new object) of a class using the new keyword,
a constructor for that class is called. Constructors are used to initialize the
instance variables (fields) of an object. Constructors are similar to methods, but
with some important differences.
The Differences
Constructor name is class name. A constructor must have the same name as the
class its in.
Default constructor.
If you define any constructor for your class, no default constructor is automatically
created.
this(...) - Calls another constructor in same class. Often a constructor with few
parameters will call a constructor with more parameters, giving default values for
the missing parameters. Use this to call other constructors in the same class.
super(...). Use super to call a constructor in a parent class. Calling the constructor
for the superclass must be the first statement in the body of a constructor. If you
are satisfied with the default constructor in the superclass, there is no need to
make a call to it because it will be supplied automatically.
Syntax:
statements...
Defining Inheritance
Inheritance is the ability to derive new classes from existing ones. A derived class
("subclass") inherits the instance variables and methods of the base class
("superclass"), and may add new instance variables and methods.
Inheritance is a relationship among classes in which one class shares the structure
and behavior of another. A subclass inherits from a superclass.
Relationships of Inheritance
“is-a” relationship
“has-a” relationship
Rules of Inheritance
• A class can only inherit from one class (known as single inheritance).
• A subclass is guaranteed to do everything the superclass can do.
• A subclass inherits members from its superclass and can modify or
add to its behavior and properties.
• A subclass can define members of the same name in the superclass,
thus hiding the superclass members.
• Inheritance is transitive (i.e., class A inherits from class B, including
what B inherited from class C).
• All classes inherit from the Object class - the highest in the
inheritance hierarchy.
• private members, hidden members, and constructors are not inherited
by subclasses.
? Questions
Activity 2:
Directions: Read and analyze each statement. Write check (/) if the statement is
correct and (x) if otherwise.
_________3. A constructor must have the same name as the class its in.
_________8. Inheritance is the ability to derive new classes from existing ones.
Directions: Analyze the given code below and answer the questions in each item.
Directions: Write a Java Program that will ask the size of the sides of the square
and two separate methods that will compute the area and perimeter of the square.
Use the given in Activity 3 as your reference. Write your code in the box below.
Rubrics for scoring
Criteria Details Points
Code Clarity Code is well-formatted and 3
and readable.
Readability
Meaningful variable and method 2
names.
Proper indentation and consistent 2
use of whitespace.
Functionality Program achieves its intended 4
and Logic purpose (e.g., calculates area, solves
a problem).
Correct usage of variables and data 2
types.
Proper implementation of loops, 3
conditions, and methods.
User Program prompts user for required 1
Interaction input.
and Input
Handles user input errors gracefully 1
Handling
(e.g., non-integer inputs).
Output and Output is clear, well-formatted, and 2
Presentation understandable.
TOTAL 15
Closure
-------------------------------------
-------------------------------------
-------------------------------------
Telefax: -------------------------