SlideShare a Scribd company logo
1 of 13
ITC 210 ® 2015
Java does not provide all the classes that
you will ever need, so it permits you to design
and implement your own classes. Therefor, you
must learn how to create your own classes.
ITC 210 ® 2015
An object of a class has both data and
operations that can be performed on that
data.
The mechanism in Java that allows you to
combine data operations on the data in a
single units is called a class.
Combining data and operations on the data is
called encapsulation.
ITC 210 ® 2015
private – you cannot access it outside the class
public – you can access it outside the class
protected
ITC 210 ® 2015
Class is a reserved word. It only defines a data
type and it announces that declaration of a
class.
The data members of a class are also called
fields.
ITC 210 ® 2015
The (non-static) methods of a class are called
the instance method of the class.
When the variable of an instance can be
changed such methods are called mutator
method.
When a instance variable does not change its
value such method are called accessor.
ITC 210 ® 2015
Constructor has the following properties:
The name of a constructor is the same name of
the class.
A constructor has not return type nor void.
A class can have more than one constructor.
If a class has more than one constructor, the
constructor must have different signatures.
Constructors execute automatically when class
objects are instantiated.
ITC 210 ® 2015
A Constructor has the same name as the
class, and it executes automatically when a
object of that class is created.
Constructors are used to guarantee that
the instance variables of the class are initialized.
Two types of constructor
1. Those with parameters
2. Those without parameters (default
constructor)
ITC 210 ® 2015
public class Person {
private String firstname;
private String lastname;
public Person()
{
firstname="";
lastname="";
}
public Person(String first, String last)
{
setName(first,last);
}
public String toString()
{
return (firstname+ " " + lastname);
}
public void setName(String first, String last)
{
firstname=first;
lastname=last;
}
public String getFirstName()
{
return firstname;
}
public String getLastName()
{
return lastname;
}
}
ITC 210 ® 2015
A class and its members can be described
graphically using Unified Modeling Language
(UML) notation.
ITC 210 ® 2015
Clock
-hr: int
-min: int
-sec: int
+Clock()
+Clock(int, int, int)
+setTime(int, int, int): void
+getHouts(); int
+getMinutes(): int
+getSeconds(); int
+printTime(): void
+incrementSecond(): int
+incrementMinutes(): int
+incrementHours(): int
+equals(Clock): boolean
+makeCopy(Copy): void
+getCopy(): Copy
Contains the name of the class
Contains the data members and their
data types
Contains the method names, parameter
list, and return types.
 The + (plus) sign in front of a member
indicates that it is a public member;
 The – (minus) sign indicates that it
is a private member.
 The # symbol before a member name
indicates that it is a protected
member.
ITC 210 ® 2015

More Related Content

What's hot

Inner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in javaInner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in javaAdil Mehmoood
 
Nested classes in java
Nested classes in javaNested classes in java
Nested classes in javaRicha Singh
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructorsJan Niño Acierto
 
Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVATech_MX
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their AccessingMuhammad Hammad Waseem
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functionsMarlom46
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Javakjkleindorfer
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in JavaRavi_Kant_Sahu
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods javaPadma Kannan
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applicationskjkleindorfer
 

What's hot (20)

Inner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in javaInner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in java
 
Nested classes in java
Nested classes in javaNested classes in java
Nested classes in java
 
Java- Nested Classes
Java- Nested ClassesJava- Nested Classes
Java- Nested Classes
 
Chap08
Chap08Chap08
Chap08
 
Inner class
Inner classInner class
Inner class
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
 
19 reflection
19   reflection19   reflection
19 reflection
 
Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVA
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in Java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Java Inner Classes
Java Inner ClassesJava Inner Classes
Java Inner Classes
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applications
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member
 

Viewers also liked

კათედრაზე გამოცდილების გაზიარების ანგარიში შეფასების რუბრიკები
კათედრაზე გამოცდილების გაზიარების ანგარიში  შეფასების რუბრიკებიკათედრაზე გამოცდილების გაზიარების ანგარიში  შეფასების რუბრიკები
კათედრაზე გამოცდილების გაზიარების ანგარიში შეფასების რუბრიკებიMaia Siradze
 
Victoria's Secret - a bombshell approach
Victoria's Secret  - a bombshell approachVictoria's Secret  - a bombshell approach
Victoria's Secret - a bombshell approachjohn swajan
 
Dzierżoniów in the past and now by dawid
Dzierżoniów in the past and now by dawidDzierżoniów in the past and now by dawid
Dzierżoniów in the past and now by dawidAnna Sz.
 
ინდივიდუალური სამოქმედო გეგმა 2016
ინდივიდუალური სამოქმედო გეგმა 2016ინდივიდუალური სამოქმედო გეგმა 2016
ინდივიდუალური სამოქმედო გეგმა 2016Maia Siradze
 
Proyecto convivencia pacífica y reflexiva
Proyecto convivencia pacífica y reflexivaProyecto convivencia pacífica y reflexiva
Proyecto convivencia pacífica y reflexivaJaime Saltarin Viloria
 
Le Fil Beauté by Extreme_n°45 juillet15
Le Fil Beauté by Extreme_n°45 juillet15Le Fil Beauté by Extreme_n°45 juillet15
Le Fil Beauté by Extreme_n°45 juillet15Extreme
 
Types of Capital Market
Types of Capital MarketTypes of Capital Market
Types of Capital MarketDisha Bhatia
 

Viewers also liked (10)

2016 resume
2016 resume2016 resume
2016 resume
 
კათედრაზე გამოცდილების გაზიარების ანგარიში შეფასების რუბრიკები
კათედრაზე გამოცდილების გაზიარების ანგარიში  შეფასების რუბრიკებიკათედრაზე გამოცდილების გაზიარების ანგარიში  შეფასების რუბრიკები
კათედრაზე გამოცდილების გაზიარების ანგარიში შეფასების რუბრიკები
 
Plan de estudio
Plan de estudioPlan de estudio
Plan de estudio
 
Victoria's Secret - a bombshell approach
Victoria's Secret  - a bombshell approachVictoria's Secret  - a bombshell approach
Victoria's Secret - a bombshell approach
 
Dzierżoniów in the past and now by dawid
Dzierżoniów in the past and now by dawidDzierżoniów in the past and now by dawid
Dzierżoniów in the past and now by dawid
 
ინდივიდუალური სამოქმედო გეგმა 2016
ინდივიდუალური სამოქმედო გეგმა 2016ინდივიდუალური სამოქმედო გეგმა 2016
ინდივიდუალური სამოქმედო გეგმა 2016
 
Collagen
CollagenCollagen
Collagen
 
Proyecto convivencia pacífica y reflexiva
Proyecto convivencia pacífica y reflexivaProyecto convivencia pacífica y reflexiva
Proyecto convivencia pacífica y reflexiva
 
Le Fil Beauté by Extreme_n°45 juillet15
Le Fil Beauté by Extreme_n°45 juillet15Le Fil Beauté by Extreme_n°45 juillet15
Le Fil Beauté by Extreme_n°45 juillet15
 
Types of Capital Market
Types of Capital MarketTypes of Capital Market
Types of Capital Market
 

Similar to Java - User Defined classes

Object oriented design
Object oriented designObject oriented design
Object oriented designlykado0dles
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methodsfarhan amjad
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceEng Teong Cheah
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptxakila m
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMambikavenkatesh2
 
Classes-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfClasses-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfismartshanker1
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptmanomkpsg
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects newlykado0dles
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ Dev Chauhan
 

Similar to Java - User Defined classes (20)

C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Object oriented design
Object oriented designObject oriented design
Object oriented design
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
Lecture 4. mte 407
Lecture 4. mte 407Lecture 4. mte 407
Lecture 4. mte 407
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & Inheritance
 
Class and object
Class and objectClass and object
Class and object
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptx
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoM
 
Classes-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfClasses-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdf
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
 
C# program structure
C# program structureC# program structure
C# program structure
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
 
Lecture22.23.07.2014
Lecture22.23.07.2014Lecture22.23.07.2014
Lecture22.23.07.2014
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
 

Recently uploaded

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Java - User Defined classes

  • 1.
  • 2. ITC 210 ® 2015 Java does not provide all the classes that you will ever need, so it permits you to design and implement your own classes. Therefor, you must learn how to create your own classes.
  • 3. ITC 210 ® 2015 An object of a class has both data and operations that can be performed on that data. The mechanism in Java that allows you to combine data operations on the data in a single units is called a class. Combining data and operations on the data is called encapsulation.
  • 4. ITC 210 ® 2015 private – you cannot access it outside the class public – you can access it outside the class protected
  • 5. ITC 210 ® 2015 Class is a reserved word. It only defines a data type and it announces that declaration of a class. The data members of a class are also called fields.
  • 6. ITC 210 ® 2015 The (non-static) methods of a class are called the instance method of the class. When the variable of an instance can be changed such methods are called mutator method. When a instance variable does not change its value such method are called accessor.
  • 7. ITC 210 ® 2015 Constructor has the following properties: The name of a constructor is the same name of the class. A constructor has not return type nor void. A class can have more than one constructor. If a class has more than one constructor, the constructor must have different signatures. Constructors execute automatically when class objects are instantiated.
  • 8. ITC 210 ® 2015 A Constructor has the same name as the class, and it executes automatically when a object of that class is created. Constructors are used to guarantee that the instance variables of the class are initialized. Two types of constructor 1. Those with parameters 2. Those without parameters (default constructor)
  • 9. ITC 210 ® 2015 public class Person { private String firstname; private String lastname; public Person() { firstname=""; lastname=""; } public Person(String first, String last) { setName(first,last); } public String toString() { return (firstname+ " " + lastname); } public void setName(String first, String last) { firstname=first; lastname=last; } public String getFirstName() { return firstname; } public String getLastName() { return lastname; } }
  • 10.
  • 11. ITC 210 ® 2015 A class and its members can be described graphically using Unified Modeling Language (UML) notation.
  • 12. ITC 210 ® 2015 Clock -hr: int -min: int -sec: int +Clock() +Clock(int, int, int) +setTime(int, int, int): void +getHouts(); int +getMinutes(): int +getSeconds(); int +printTime(): void +incrementSecond(): int +incrementMinutes(): int +incrementHours(): int +equals(Clock): boolean +makeCopy(Copy): void +getCopy(): Copy Contains the name of the class Contains the data members and their data types Contains the method names, parameter list, and return types.  The + (plus) sign in front of a member indicates that it is a public member;  The – (minus) sign indicates that it is a private member.  The # symbol before a member name indicates that it is a protected member.
  • 13. ITC 210 ® 2015