Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
27 views

Week2 Classes and Object

The document discusses classes and objects in Java. A class is a blueprint or template for objects and defines variables and methods but does not use memory. An object is an instance of a class created through instantiation, which allocates memory and allows access to class variables and methods. Instantiation uses the new keyword to create an object from a class.

Uploaded by

bpmaquilla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Week2 Classes and Object

The document discusses classes and objects in Java. A class is a blueprint or template for objects and defines variables and methods but does not use memory. An object is an instance of a class created through instantiation, which allocates memory and allows access to class variables and methods. Instantiation uses the new keyword to create an object from a class.

Uploaded by

bpmaquilla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Classes & Object

Lesson Objectives:

• What is a Class
• Class Syntax
• What is an Object?
• Instantiation
• Sample Outputs
What is a Class?
What is a Class?
• It is a blueprint or template of an object that contains variables for storing
data and functions to perform operations on the data (e.g. SmartPhone
Class)

• It will not occupy any memory space.


Class can contain..

• Class Field (Properties or Attributes)


• Methods (Operations or Actions)
• Constructors
• Blocks
• Nested Class Interface
A Ball as a Class
Class Syntax
<access modifier> class <className> {

<access modifier> data_type <fieldname>;


….
<access modifier> <methodName>() {
//method body
}

}
A class name should:
• start with the uppercase letter.
• be a noun such as Color, Button, System, Thread, etc.
• Use appropriate words, instead of acronyms.
• No spaces in between (if the class name is more than one word eg. UserAccount)
Example Code:
Example Code:
What is an
Object?
What is an Object?
• Objects or instance of a class are key to understanding object-oriented
technology.
• State (in programming, known as classfield
Properties, attribute, data members) and behavior
(in programming, known as methods)
What is an Object?
Instantiation
Instantiation
• The process of creating an object from an existing class (template).
• To make you need to:
• Start from a class
• Copy an existing project.
Instantiation Syntax
• In java, the new keyword will enable us to create an object.
• <className> <objectName> = new <className>();

Example:
Car audi = new Car();
Instantiation Syntax
Instantiation Syntax
Instantiation Syntax
Summary:
• A class is a blueprint or a template of Java Object.
• An object is considered an object instance through instantiation which
contains state (which is known as classfield) and behavior (known as
methods.)
• Instantiation is the process of creating object.
Sources:
[1] P. Chawla, “Introduction of Object Oriented Programming”, [Online]. Available:
https://shorturl.at/msAMV. [Accessed: 16-July-2022].
[2] w3Schools, “The Java Tutorials”, [Online]. Available:
https://www.w3schools.com/java/default.asp. [Accessed: 17-July-2022].
[3] C-sharp Corner, “Introduction to Object Oriented Programming Concepts in C#”,
[Online]. Available:
https://www.csharpcorner.com/UploadFile/mkagrahari/introduction-to-object-
orientedprogramming-concepts-in-C-Sharp/. [Accessed: 17-July-2022].
Thank you!
Activity
Activity
From the given image, create your own Java Program to illustrate a Dog
class named Dog.java that will contain the given set of class field. A main
method will also be created in order to execute the program by creating an
object instance named “Bruno” with the class field values as shown in the
given image. Print the values of class fields of the Dog object created in the
Java Console window.
Activity 1:

Bruno

You might also like