SlideShare a Scribd company logo
Object-oriented
Programming
At the end of this chapter, the learner will be able to:
1) Define classes and objects.
2) Use abstraction and encapsulation to simplify
complicated problems.
3) Utilize inheritance and polymorphism in Java.
4) Define and use abstract classes.
5) Define and implement interfaces.
A L ABELEE IT LearningSeries Your First Java Book ©2009
What is Java?
• It is an object-oriented programming language.
Class:
(blueprint)
Book
Properties
Object:
(instance)
Textbook
Properties
title
author
yearPublished
Your First Java Book
Lesley Abe
2009
Methods Methods
borrow
return
borrow
return
A L ABELEE IT LearningSeries Your First Java Book ©2009
Object Oriented Programming
• Abstraction
– Modeling classes (UML class diagrams)
• Encapsulation
– One object: data and behavior combined
– Information Hiding
• Access levels: private, protected, public, default
– Accessors (get) and Mutators (set)
– interface
• Inheritance
– Superclass and subclass
• Polymorphism
– Overloading
– overriding
A L ABELEE IT LearningSeries Your First Java Book ©2009
Abstraction and Encapsulation
Trainer
-name:String
-height:double
-weight:double
-birthday:Date
+talk(String)
+getName():String
+setName(String)
<<constructor>>
+Trainer()
+Trainer(String,
double, double,
Date)
Name of Class
Attributes/properties
Methods
Trainee
-name:String
-height:double
-weight:double
-birthday:Date
-traineeNumber:int
+talk(String)
+getName():String
+setName(String)
<<constructor>>
+Trainee()
+Trainee(int,String,
double, double,
Date)
Examples:
Accessor (Method)
Mutator (Method)
Default Constructor
Overloaded Constructor
A L ABELEE IT LearningSeries Your First Java Book ©2009
Java Class Implementation
import java.util.Date;
public class Trainer{
private String name;
private double height; //height in cm
private double weight; //weight in kg
private Date birthday;
public Trainer(){ } //Java provides a default constructor when it is not created by the programmer
public Trainer(String name, double height, double weight, Date birthday) {
this.name = name;
this.height = height;
this.weight = weight;
this.birthday = birthday;
}
public void talk(String phrase){
System.out.println(phrase);
}
public String getName() {return name;}
public void setName(String name) {this.name=name;}
}
• Members
– Attributes/fields (Variables) and
methods
• Scope
– Variable and method visibility,
and accessibility
A L ABELEE IT LearningSeries Your First Java Book ©2009
Constructors
public Trainer(){ }
//Java provides a default constructor when it is not created by the programmer
// Always provide a default constructor,s specially when overloading a constructor.
public Trainer (String name, Date birthday) {
this.name = name;
this.height = 180.5;
this.weight = 45.5;
this.birthday = birthday;
}
public Trainer (String name, double height, double weight, Date
birthday) {
this(name, birthday);
this.height = height;
this.weight = weight;
}
//Constructors have no return type. They are called in creating objects, using new.
Modifiers
method name
parameter list in parenthesis
method body, enclosed between
braces
Use this to make a call to another
constructor and it must be in the
constructor’s first line.
A L ABELEE IT LearningSeries Your First Java Book ©2009
Mutator and Accessor
//Accessors have no parameter list. Prefix with get.
public String getName ( ) {return name;}
//Mutators are setters thus they return nothing or void. Prefix with set.
public void setName (String name) {this.name=name;}
modifiers
return type
method name
parameter list in parenthesis
method body, enclosed between
braces
A L ABELEE IT LearningSeries Your First Java Book ©2009
Method Declaration
//method names are verbs
//or verb phrases
public void talk (String phrase){
//declare local variables (only visible
// within the method)
// before they are used
System.out.println(phrase);
}
public static void main (String[] args) throws IOException{
//no need to declare parameters
System.out.print(args[0]);
}
modifiers
return type
method name
parameter (formal) list in
parenthesis
exception list
method body, enclosed between
braces
A L ABELEE IT LearningSeries Your First Java Book ©2009
Access Level
Access
Modifier
Within the
Same
Class
Within the
Same
Package
Within a
Subclass
public Accessible Accessible Accessible
protected Accessible Accessible Accessible
default Accessible Accessible
private Accessible
A L ABELEE IT LearningSeries Your First Java Book ©2009
Coding Conventions
• Camel Case (first letter of the first word is in lowercase,
every first letter of the succeeding words are capitalized,
e.g. isUpdated)
– Class member variables (use Hungarian notation)
– Method parameters
– Methods (Mutators, Accessors)
• Pascal Case (every first letter of the every word is
capitalized, e.g. MyAccount)
– Classes
– Constructors
• ALL CAPS
– Constants (each word separated by underscore)
A L ABELEE IT LearningSeries Your First Java Book ©2009
Scope
• The scope of a variable is defined by where a variable is declared.
In Java, the closest declaration is considered first.
• The this keyword
– To refer to methods of the current class
this.methodName(<parameter/s>)
– To refer to variables of the current class
this.variableName
– To refer to the constructor of the current class
this(<parameter/s>);
for(int ctr=0;ctr<=10;ctr++) System.out.println(ctr);
if(ctr==10) System.out.println(ctr);//error
A L ABELEE IT LearningSeries Your First Java Book ©2009
Variable and Method Invocation
• To declare a new instance of a class, use the syntax:
ClassName objectName = new Constructor(<parameter/s>);
• Invoking/calling Methods
<objectName>.<methodName>(<parameter/s>);
• Invoking Variables
<objectName>.<variableName>;
import java.util.Date;
public class MainClass {
public static void main(String[] args){
Trainer myTrainer = new Trainer(“Splinter”, 150, 50, new Date());
myTrainer.talk(“My name is “+myTrainer.getName());
myTrainer.talk(“I will be your trainer.”);
}
}
parameter (actual) list in
parenthesis
A L ABELEE IT LearningSeries Your First Java Book ©2009
Instance and Class Members
• class member
– all instances of a class share a variable/method
– defined with the keyword static.
– Invoking Methods
<ClassName>.<methodName>(<parameter/s>)
– Invoking Variables
<ClassName>.<variableName>
• instance member
– every object instantiated from that class contains its own copy of
the variable/method
A L ABELEE IT LearningSeries Your First Java Book ©2009
Inheritance
Trainer
<<constructor>>
Trainer(String, double,
double, Date)
Trainee
traineeNumber:int
+getTraineeNumber():int
<<constructor>>
Trainee(String, double,
double, Date)
Human
#name:String
#height:double
#weight:double
#birthday:Date
+talk(String)
+getName():String
+setName(String)
<<constructor>>
Human(String,double
,double,int)
A L ABELEE IT LearningSeries Your First Java Book ©2009
Inheritance
public class Human{
private String name; //What if we made this private? (Originally protected)
protected double height; //height in cm
protected double weight; //weight in kg
protected Date birthday;
public Human(String name, double height, double weight, Date birthday){
this.name = name;
this.height = height;
this.weight = weight;
this.birthday = birthday;
}
public void talk(String phrase){
System.out.println(phrase);
}
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
// other methods may be implemented
}
public class Trainee extends Human{
static int traineeNumber=0; //class member
public Trainee(){ traineeNumber++; }
public Trainee(String name, double height, double
weight, Date birthday){
super(name, height, weight, birthday);
traineeNumber++;
}
public static int getTraineeNumber(){
return traineeNumber;
}
}
A L ABELEE IT LearningSeries Your First Java Book ©2009
Inheritance
• The super keyword
– To refer to methods of the parent class
super.methodName(<parameter/s>)
– To refer to variables of the parent class
super.variableName
– To refer to the constructor of the parent class
super(<parameter/s>);
Note: super MUST be the first line in the method.
• Single Inheritance
– a class can inherit from only one superclass
A L ABELEE IT LearningSeries Your First Java Book ©2009
Polymorphism
public double computeIdealBodyWeight(){
return 50 + 2.3 *( height/2.4 - 60 );
}
}
package Chapter8.inheritance;
public class Human{
protected String name;
protected double height; //height in cm
protected double weight; //weight
protected Date birthday;
public Human(String name, double height,
double weight, Date birthday)
{
this.name = name;
this.height = height;
this.weight = weight;
this.birthday = birthday;
}
public void talk(String phrase){
System.out.println(phrase);
}
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
package Chapter8.inheritance;
public class Woman extends Human
{
public Woman(String name, double height, double
weight, int birthday){
super(name, height, weight, birthday);
}
public double computeIdealBodyWeight(){
return 45.5 + 2.3 *(getHeight()/2.4 - 60 );
}
}
Method
Overriding
Although they may have the
same method signature,
Overriding method cannot be
less accessible than the method
it is overriding.
A L ABELEE IT LearningSeries Your First Java Book ©2009
Polymorphism
public class Athlete2 extends Human {
boolean isMale = true;
public Athlete2(String name, double height, double weight, Date birthday){
super(name, height, weight, birthday);
}
public Athlete2(String name, double height, double weight, Date birthday, boolean isMale){
this(name, height, weight, birthday);
this.isMale = isMale;
}
public double ComputeIdealBodyWeight(){
if (isMale){
return super.ComputeIdealBodyWeight();
}
else{
return 45.5 + 2.3 *(getHeight()/2.4 - 60 );
}
}
}
Method
Overloading
Overloaded methods have the
same method name but different
parameter/s (type, order). Each
method must be unique in a
class.
A L ABELEE IT LearningSeries Your First Java Book ©2009
Abstract class
Trainer
<<constructor>>
Trainer(String,
double, double,
Date)
computeIdealBodyWeight():
double
Trainee
traineeNumber:int
+getTraineeNumber():int
<<constructor>>
Trainee(String, double,
double, Date)
computeIdealBodyWeight():double
{abstract}
Human
-name:String
-height:double
-weight:double
-birthday:Date
+talk(String)
+getName():String
+setName(String)
+{abstract}
computeIdealBodyWeight(
):double
<<constructor>>
Human(String,double,dou
ble,int)
A L ABELEE IT LearningSeries Your First Java Book ©2009
Abstract Classpackage Chapter8.inheritance;
public abstract class AbstractHuman{
protected String name;
protected double height; //height in cm
protected double weight; //weight in kg
protected Date birthday;
public AbstractHuman(String name, double height, double weight, Date birthday){
this.name = name; this.height = height; this.weight = weight; this. birthday = birthday;
}
public void talk(String phrase){
System.out.println(phrase);
}
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public void setHeight(double height){
this.height = height;
}
public double getHeight(){
return this.height;
}
public abstract double computeIdealBodyWeight();
}
Subclasses must override this method
Abstract classes cannot be instantiated.
A L ABELEE IT LearningSeries Your First Java Book ©2009
Interface
public interface <interface_Name>{
  //constant variable declarations
  //method signatures
}
• Interfaces are used to simulate multiple inheritance.
Note:
A solid arrow is used to depict inheritance when a class extends another.
For example, EmployeeTrainer extends the Human class. A dashed arrow is
used to imply that a class implements an interface. For example,
EmployeeTrainer implements the Employee interface.
A L ABELEE IT LearningSeries Your First Java Book ©2009
Interface
EmployeeTrainer
-salary:double
<<constructor>>
EmployeeTrainer
(String, double,
double, Date)
<<interface>>
Employee
+getSalary():double
+setSalary(double)
Human
-name:String
-height:double
-weight:double
-birthday:Date
+talk(String)
+getName():String
+setName(String)
<<constructor>>
Human(String,double
,double, Date
A L ABELEE IT LearningSeries Your First Java Book ©2009
Interface
public interface Employee {
public double getSalary();
public void setSalary(double);
}
public class EmployeeTrainer extends Human implements Employee{
private double salary;
public EmployeeTrainer(String name, double height, double weight, Date bday){
super(name, height, weight, bday);
}
public double getSalary() { return salary; }
public void setSalary(double) {this.salary= salary; }
}
A L ABELEE IT LearningSeries Your First Java Book ©2009
Review
• Define the following:
– Abstraction
– Encapsulation
– Inheritance
– Interface
– Abstract class
– Polymorphism
– Superclass
– subclass
• Give an example of a
UML class diagram.
• What is the difference
between class members
and instance members?
• What is the difference
between overloading
and overriding?
• Differentiate the
following: public,
private, protected

More Related Content

What's hot

Java chapter 4
Java chapter 4Java chapter 4
Java chapter 4
Abdii Rashid
 
Introduction to php oop
Introduction to php oopIntroduction to php oop
Java class 3
Java class 3Java class 3
Java class 3
Edureka!
 
Java class 6
Java class 6Java class 6
Java class 6
Edureka!
 
Design patterns(red)
Design patterns(red)Design patterns(red)
Design patterns(red)
Fahad A. Shaikh
 
Fast Forward To Scala
Fast Forward To ScalaFast Forward To Scala
Fast Forward To Scala
Martin Kneissl
 
Java class 4
Java class 4Java class 4
Java class 4
Edureka!
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
Glenn Guden
 
Java Unit 2(Part 1)
Java Unit 2(Part 1)Java Unit 2(Part 1)
Java Unit 2(Part 1)
SURBHI SAROHA
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Maulik Borsaniya
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
OUM SAOKOSAL
 
Lecture 2 classes i
Lecture 2 classes iLecture 2 classes i
Lecture 2 classes i
the_wumberlog
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
Ólafur Andri Ragnarsson
 
0 E158 C10d01
0 E158 C10d010 E158 C10d01
0 E158 C10d01
nikeshhayaran
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
SURBHI SAROHA
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
SURBHI SAROHA
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
Lakshmi Sarvani Videla
 
Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)
SURBHI SAROHA
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
HarshitaAshwani
 

What's hot (19)

Java chapter 4
Java chapter 4Java chapter 4
Java chapter 4
 
Introduction to php oop
Introduction to php oopIntroduction to php oop
Introduction to php oop
 
Java class 3
Java class 3Java class 3
Java class 3
 
Java class 6
Java class 6Java class 6
Java class 6
 
Design patterns(red)
Design patterns(red)Design patterns(red)
Design patterns(red)
 
Fast Forward To Scala
Fast Forward To ScalaFast Forward To Scala
Fast Forward To Scala
 
Java class 4
Java class 4Java class 4
Java class 4
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
 
Java Unit 2(Part 1)
Java Unit 2(Part 1)Java Unit 2(Part 1)
Java Unit 2(Part 1)
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
 
Lecture 2 classes i
Lecture 2 classes iLecture 2 classes i
Lecture 2 classes i
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
 
0 E158 C10d01
0 E158 C10d010 E158 C10d01
0 E158 C10d01
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
 
Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 

Similar to Lecture Notes

Learn java
Learn javaLearn java
Learn java
Palahuja
 
Computer programming 2 -lesson 4
Computer programming 2  -lesson 4Computer programming 2  -lesson 4
Computer programming 2 -lesson 4
MLG College of Learning, Inc
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
Ramrao Desai
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
rajkamaltibacademy
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
Sherihan Anver
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
mha4
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
mha4
 
inheritance.pptx
inheritance.pptxinheritance.pptx
inheritance.pptx
sonukumarjha12
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objects
mcollison
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
Rakesh Madugula
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
Shivam Singhal
 
Java Simple Notes
Java Simple NotesJava Simple Notes
Java Simple Notes
ashish kumar
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Connex
 
Java02
Java02Java02
Take the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphpTake the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphp
Alena Holligan
 
Reflection
ReflectionReflection
Reflection
Piyush Mittal
 
JavaScript OOP
JavaScript OOPJavaScript OOP
JavaScript OOP
Doncho Minkov
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.ppt
RithwikRanjan
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
Fajar Baskoro
 

Similar to Lecture Notes (20)

Learn java
Learn javaLearn java
Learn java
 
Computer programming 2 -lesson 4
Computer programming 2  -lesson 4Computer programming 2  -lesson 4
Computer programming 2 -lesson 4
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
inheritance.pptx
inheritance.pptxinheritance.pptx
inheritance.pptx
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objects
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Java Simple Notes
Java Simple NotesJava Simple Notes
Java Simple Notes
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Java02
Java02Java02
Java02
 
Take the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphpTake the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphp
 
Reflection
ReflectionReflection
Reflection
 
JavaScript OOP
JavaScript OOPJavaScript OOP
JavaScript OOP
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.ppt
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 

More from Dwight Sabio

Human Rights Observatory Description
Human Rights Observatory DescriptionHuman Rights Observatory Description
Human Rights Observatory Description
Dwight Sabio
 
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITORRIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
Dwight Sabio
 
Report on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their SituationReport on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their Situation
Dwight Sabio
 
Gender ombud report 2016 final
Gender ombud report 2016 finalGender ombud report 2016 final
Gender ombud report 2016 final
Dwight Sabio
 
Strengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of genderStrengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of gender
Dwight Sabio
 
IP Report
IP ReportIP Report
IP Report
Dwight Sabio
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt file
Dwight Sabio
 
Ch3OperSys
Ch3OperSysCh3OperSys
Ch3OperSys
Dwight Sabio
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3
Dwight Sabio
 
ABC Supermarket
ABC SupermarketABC Supermarket
ABC Supermarket
Dwight Sabio
 
Programming Problem 3
Programming Problem 3Programming Problem 3
Programming Problem 3
Dwight Sabio
 
Lab Activity
Lab ActivityLab Activity
Lab Activity
Dwight Sabio
 
Bluetooth
Bluetooth Bluetooth
Bluetooth
Dwight Sabio
 
Programming Problem 2
Programming Problem 2Programming Problem 2
Programming Problem 2
Dwight Sabio
 
Arduino e-book
Arduino e-bookArduino e-book
Arduino e-book
Dwight Sabio
 
Midterm Project Specification
Midterm Project Specification Midterm Project Specification
Midterm Project Specification
Dwight Sabio
 
Game Design Document
Game Design DocumentGame Design Document
Game Design Document
Dwight Sabio
 
Class diagram
Class diagramClass diagram
Class diagram
Dwight Sabio
 
Midterm Project
Midterm Project Midterm Project
Midterm Project
Dwight Sabio
 
ProgrammingProblem
ProgrammingProblemProgrammingProblem
ProgrammingProblem
Dwight Sabio
 

More from Dwight Sabio (20)

Human Rights Observatory Description
Human Rights Observatory DescriptionHuman Rights Observatory Description
Human Rights Observatory Description
 
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITORRIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
 
Report on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their SituationReport on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their Situation
 
Gender ombud report 2016 final
Gender ombud report 2016 finalGender ombud report 2016 final
Gender ombud report 2016 final
 
Strengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of genderStrengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of gender
 
IP Report
IP ReportIP Report
IP Report
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt file
 
Ch3OperSys
Ch3OperSysCh3OperSys
Ch3OperSys
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3
 
ABC Supermarket
ABC SupermarketABC Supermarket
ABC Supermarket
 
Programming Problem 3
Programming Problem 3Programming Problem 3
Programming Problem 3
 
Lab Activity
Lab ActivityLab Activity
Lab Activity
 
Bluetooth
Bluetooth Bluetooth
Bluetooth
 
Programming Problem 2
Programming Problem 2Programming Problem 2
Programming Problem 2
 
Arduino e-book
Arduino e-bookArduino e-book
Arduino e-book
 
Midterm Project Specification
Midterm Project Specification Midterm Project Specification
Midterm Project Specification
 
Game Design Document
Game Design DocumentGame Design Document
Game Design Document
 
Class diagram
Class diagramClass diagram
Class diagram
 
Midterm Project
Midterm Project Midterm Project
Midterm Project
 
ProgrammingProblem
ProgrammingProblemProgrammingProblem
ProgrammingProblem
 

Recently uploaded

SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 

Recently uploaded (20)

SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 

Lecture Notes

  • 1. Object-oriented Programming At the end of this chapter, the learner will be able to: 1) Define classes and objects. 2) Use abstraction and encapsulation to simplify complicated problems. 3) Utilize inheritance and polymorphism in Java. 4) Define and use abstract classes. 5) Define and implement interfaces.
  • 2. A L ABELEE IT LearningSeries Your First Java Book ©2009 What is Java? • It is an object-oriented programming language. Class: (blueprint) Book Properties Object: (instance) Textbook Properties title author yearPublished Your First Java Book Lesley Abe 2009 Methods Methods borrow return borrow return
  • 3. A L ABELEE IT LearningSeries Your First Java Book ©2009 Object Oriented Programming • Abstraction – Modeling classes (UML class diagrams) • Encapsulation – One object: data and behavior combined – Information Hiding • Access levels: private, protected, public, default – Accessors (get) and Mutators (set) – interface • Inheritance – Superclass and subclass • Polymorphism – Overloading – overriding
  • 4. A L ABELEE IT LearningSeries Your First Java Book ©2009 Abstraction and Encapsulation Trainer -name:String -height:double -weight:double -birthday:Date +talk(String) +getName():String +setName(String) <<constructor>> +Trainer() +Trainer(String, double, double, Date) Name of Class Attributes/properties Methods Trainee -name:String -height:double -weight:double -birthday:Date -traineeNumber:int +talk(String) +getName():String +setName(String) <<constructor>> +Trainee() +Trainee(int,String, double, double, Date) Examples: Accessor (Method) Mutator (Method) Default Constructor Overloaded Constructor
  • 5. A L ABELEE IT LearningSeries Your First Java Book ©2009 Java Class Implementation import java.util.Date; public class Trainer{ private String name; private double height; //height in cm private double weight; //weight in kg private Date birthday; public Trainer(){ } //Java provides a default constructor when it is not created by the programmer public Trainer(String name, double height, double weight, Date birthday) { this.name = name; this.height = height; this.weight = weight; this.birthday = birthday; } public void talk(String phrase){ System.out.println(phrase); } public String getName() {return name;} public void setName(String name) {this.name=name;} } • Members – Attributes/fields (Variables) and methods • Scope – Variable and method visibility, and accessibility
  • 6. A L ABELEE IT LearningSeries Your First Java Book ©2009 Constructors public Trainer(){ } //Java provides a default constructor when it is not created by the programmer // Always provide a default constructor,s specially when overloading a constructor. public Trainer (String name, Date birthday) { this.name = name; this.height = 180.5; this.weight = 45.5; this.birthday = birthday; } public Trainer (String name, double height, double weight, Date birthday) { this(name, birthday); this.height = height; this.weight = weight; } //Constructors have no return type. They are called in creating objects, using new. Modifiers method name parameter list in parenthesis method body, enclosed between braces Use this to make a call to another constructor and it must be in the constructor’s first line.
  • 7. A L ABELEE IT LearningSeries Your First Java Book ©2009 Mutator and Accessor //Accessors have no parameter list. Prefix with get. public String getName ( ) {return name;} //Mutators are setters thus they return nothing or void. Prefix with set. public void setName (String name) {this.name=name;} modifiers return type method name parameter list in parenthesis method body, enclosed between braces
  • 8. A L ABELEE IT LearningSeries Your First Java Book ©2009 Method Declaration //method names are verbs //or verb phrases public void talk (String phrase){ //declare local variables (only visible // within the method) // before they are used System.out.println(phrase); } public static void main (String[] args) throws IOException{ //no need to declare parameters System.out.print(args[0]); } modifiers return type method name parameter (formal) list in parenthesis exception list method body, enclosed between braces
  • 9. A L ABELEE IT LearningSeries Your First Java Book ©2009 Access Level Access Modifier Within the Same Class Within the Same Package Within a Subclass public Accessible Accessible Accessible protected Accessible Accessible Accessible default Accessible Accessible private Accessible
  • 10. A L ABELEE IT LearningSeries Your First Java Book ©2009 Coding Conventions • Camel Case (first letter of the first word is in lowercase, every first letter of the succeeding words are capitalized, e.g. isUpdated) – Class member variables (use Hungarian notation) – Method parameters – Methods (Mutators, Accessors) • Pascal Case (every first letter of the every word is capitalized, e.g. MyAccount) – Classes – Constructors • ALL CAPS – Constants (each word separated by underscore)
  • 11. A L ABELEE IT LearningSeries Your First Java Book ©2009 Scope • The scope of a variable is defined by where a variable is declared. In Java, the closest declaration is considered first. • The this keyword – To refer to methods of the current class this.methodName(<parameter/s>) – To refer to variables of the current class this.variableName – To refer to the constructor of the current class this(<parameter/s>); for(int ctr=0;ctr<=10;ctr++) System.out.println(ctr); if(ctr==10) System.out.println(ctr);//error
  • 12. A L ABELEE IT LearningSeries Your First Java Book ©2009 Variable and Method Invocation • To declare a new instance of a class, use the syntax: ClassName objectName = new Constructor(<parameter/s>); • Invoking/calling Methods <objectName>.<methodName>(<parameter/s>); • Invoking Variables <objectName>.<variableName>; import java.util.Date; public class MainClass { public static void main(String[] args){ Trainer myTrainer = new Trainer(“Splinter”, 150, 50, new Date()); myTrainer.talk(“My name is “+myTrainer.getName()); myTrainer.talk(“I will be your trainer.”); } } parameter (actual) list in parenthesis
  • 13. A L ABELEE IT LearningSeries Your First Java Book ©2009 Instance and Class Members • class member – all instances of a class share a variable/method – defined with the keyword static. – Invoking Methods <ClassName>.<methodName>(<parameter/s>) – Invoking Variables <ClassName>.<variableName> • instance member – every object instantiated from that class contains its own copy of the variable/method
  • 14. A L ABELEE IT LearningSeries Your First Java Book ©2009 Inheritance Trainer <<constructor>> Trainer(String, double, double, Date) Trainee traineeNumber:int +getTraineeNumber():int <<constructor>> Trainee(String, double, double, Date) Human #name:String #height:double #weight:double #birthday:Date +talk(String) +getName():String +setName(String) <<constructor>> Human(String,double ,double,int)
  • 15. A L ABELEE IT LearningSeries Your First Java Book ©2009 Inheritance public class Human{ private String name; //What if we made this private? (Originally protected) protected double height; //height in cm protected double weight; //weight in kg protected Date birthday; public Human(String name, double height, double weight, Date birthday){ this.name = name; this.height = height; this.weight = weight; this.birthday = birthday; } public void talk(String phrase){ System.out.println(phrase); } public void setName(String name){ this.name = name; } public String getName(){ return this.name; } // other methods may be implemented } public class Trainee extends Human{ static int traineeNumber=0; //class member public Trainee(){ traineeNumber++; } public Trainee(String name, double height, double weight, Date birthday){ super(name, height, weight, birthday); traineeNumber++; } public static int getTraineeNumber(){ return traineeNumber; } }
  • 16. A L ABELEE IT LearningSeries Your First Java Book ©2009 Inheritance • The super keyword – To refer to methods of the parent class super.methodName(<parameter/s>) – To refer to variables of the parent class super.variableName – To refer to the constructor of the parent class super(<parameter/s>); Note: super MUST be the first line in the method. • Single Inheritance – a class can inherit from only one superclass
  • 17. A L ABELEE IT LearningSeries Your First Java Book ©2009 Polymorphism public double computeIdealBodyWeight(){ return 50 + 2.3 *( height/2.4 - 60 ); } } package Chapter8.inheritance; public class Human{ protected String name; protected double height; //height in cm protected double weight; //weight protected Date birthday; public Human(String name, double height, double weight, Date birthday) { this.name = name; this.height = height; this.weight = weight; this.birthday = birthday; } public void talk(String phrase){ System.out.println(phrase); } public void setName(String name){ this.name = name; } public String getName(){ return this.name; } package Chapter8.inheritance; public class Woman extends Human { public Woman(String name, double height, double weight, int birthday){ super(name, height, weight, birthday); } public double computeIdealBodyWeight(){ return 45.5 + 2.3 *(getHeight()/2.4 - 60 ); } } Method Overriding Although they may have the same method signature, Overriding method cannot be less accessible than the method it is overriding.
  • 18. A L ABELEE IT LearningSeries Your First Java Book ©2009 Polymorphism public class Athlete2 extends Human { boolean isMale = true; public Athlete2(String name, double height, double weight, Date birthday){ super(name, height, weight, birthday); } public Athlete2(String name, double height, double weight, Date birthday, boolean isMale){ this(name, height, weight, birthday); this.isMale = isMale; } public double ComputeIdealBodyWeight(){ if (isMale){ return super.ComputeIdealBodyWeight(); } else{ return 45.5 + 2.3 *(getHeight()/2.4 - 60 ); } } } Method Overloading Overloaded methods have the same method name but different parameter/s (type, order). Each method must be unique in a class.
  • 19. A L ABELEE IT LearningSeries Your First Java Book ©2009 Abstract class Trainer <<constructor>> Trainer(String, double, double, Date) computeIdealBodyWeight(): double Trainee traineeNumber:int +getTraineeNumber():int <<constructor>> Trainee(String, double, double, Date) computeIdealBodyWeight():double {abstract} Human -name:String -height:double -weight:double -birthday:Date +talk(String) +getName():String +setName(String) +{abstract} computeIdealBodyWeight( ):double <<constructor>> Human(String,double,dou ble,int)
  • 20. A L ABELEE IT LearningSeries Your First Java Book ©2009 Abstract Classpackage Chapter8.inheritance; public abstract class AbstractHuman{ protected String name; protected double height; //height in cm protected double weight; //weight in kg protected Date birthday; public AbstractHuman(String name, double height, double weight, Date birthday){ this.name = name; this.height = height; this.weight = weight; this. birthday = birthday; } public void talk(String phrase){ System.out.println(phrase); } public void setName(String name){ this.name = name; } public String getName(){ return this.name; } public void setHeight(double height){ this.height = height; } public double getHeight(){ return this.height; } public abstract double computeIdealBodyWeight(); } Subclasses must override this method Abstract classes cannot be instantiated.
  • 21. A L ABELEE IT LearningSeries Your First Java Book ©2009 Interface public interface <interface_Name>{   //constant variable declarations   //method signatures } • Interfaces are used to simulate multiple inheritance. Note: A solid arrow is used to depict inheritance when a class extends another. For example, EmployeeTrainer extends the Human class. A dashed arrow is used to imply that a class implements an interface. For example, EmployeeTrainer implements the Employee interface.
  • 22. A L ABELEE IT LearningSeries Your First Java Book ©2009 Interface EmployeeTrainer -salary:double <<constructor>> EmployeeTrainer (String, double, double, Date) <<interface>> Employee +getSalary():double +setSalary(double) Human -name:String -height:double -weight:double -birthday:Date +talk(String) +getName():String +setName(String) <<constructor>> Human(String,double ,double, Date
  • 23. A L ABELEE IT LearningSeries Your First Java Book ©2009 Interface public interface Employee { public double getSalary(); public void setSalary(double); } public class EmployeeTrainer extends Human implements Employee{ private double salary; public EmployeeTrainer(String name, double height, double weight, Date bday){ super(name, height, weight, bday); } public double getSalary() { return salary; } public void setSalary(double) {this.salary= salary; } }
  • 24. A L ABELEE IT LearningSeries Your First Java Book ©2009 Review • Define the following: – Abstraction – Encapsulation – Inheritance – Interface – Abstract class – Polymorphism – Superclass – subclass • Give an example of a UML class diagram. • What is the difference between class members and instance members? • What is the difference between overloading and overriding? • Differentiate the following: public, private, protected