Professional Documents
Culture Documents
Topic 3 Part 1
Topic 3 Part 1
OBJECT ORIENTED
PROGRAMMING
Topic 3:
Basic Concepts Of Classes
(Part 1)
TOPIC COVERED
Class concept
Class definition
Data members
Constant
Access specifiers (private and public)
Basic types of methods
Methods definition (methods in a concrete class)
JAVA PROGRAM ANATOMY
CLASS OBJECT
Class Program App Program
Account
-name : String
(-) data members
-ID : long
private
-balance : double
modifier
+Account()
+Account(String, int, double)
+Account (Account)
(+) +setAccount(String, int, double) : void
public +getName() : String methods
modifier +getID() : long
+getBalance() : double
+calculateNewBalance(double) : double
+toString() : String
JAVA CLASS
{
private String name; //Data member
…….
}
DATA MEMBERS
DATA MEMBER
//methods
}
MODIFIERS
MODIFIER
//methods
…
}
METHODS
METHOD
3 types of constructors
1. Default constructor (without parameters)
2. Normal constructor (with parameters )
3. Copy constructor
METHODS –
CONSTRUCTOR
(DEFAULT)
DEFAULT CONSTRUCTOR
public Account ()
{
name = null;
ID = 0;
balance = 0.0;
}
METHODS –
CONSTRUCTOR
(NORMAL)
NORMAL CONSTRUCTOR
set method
Is to change one or more of an object’s
values after the object is created and
initialized
It does not return any value, void method.
variables
MUTATOR
EXAMPLE 1
get method
Is to retrieve the values stored in object’s
variables
Returns a value
Example 1 (toString)
public String toString()
{
return (“Name :”+ name + “\nID:” + ID
+ “\nBalance :” + balance);
}
2. display() - is a method that display a string
representation of an object attributes
Account
-name : String
-ID : long data members
-balance : double
+Account()
+Account(String, int, double)
+Account (Account)
+setAccount(String, int, double) : void
+getName() : String methods
+getID() : long
+getBalance() : double
+calculateNewBalance(double) : double
+toString() : String
TEST YOURSELF
2. Data members
3. Constructors
Default
Normal
Copy
4. Methods
Mutator
Accessor
Printer
MORE READING