Introduction to Programming G50PRO University of Nottingham Unit 9 : Classes and objects Paul Tennent http://paultennent.wordpress.com/G50PRO.html Paul.tennent@nottingham.ac.uk.

Slides:



Advertisements
Similar presentations
Phil Campbell London South Bank University Java 1 First Steps.
Advertisements

Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, toString reading: self-checks: #13-18,
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
1 Classes Overview l Classes as Types l Declaring Instance Variables l Implementing Methods l Constructors l Accessor and Mutator Methods.
Classes and Instances. Introduction Classes, Objects, Methods and Instance Variables Declaring a Class with a Method and Instantiating an Object of a.
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
OOPDA Review. Terminology class-A template defining state and behavior class-A template defining state and behavior object-An instance of a class object-An.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Introduction To Object-Oriented Programming. Object-Oriented Programming Class: Code that defines the behavior of a Java programming element called an.
Object Oriented Programming Concepts OOP – reasoning about a program as a set of objects rather than as a set of actions Object – a programming entity.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Introduction to Object-Oriented Programming
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
1 Objects and Classes. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object represents an entity.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, this reading: self-checks: #13-17 exercises:
CS1201: Programming Language 2 Classes and objects By: Nouf Aljaffan Edited by : Nouf Almunyif.
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
Objects and Classes Mostafa Abdallah
Object Oriented Programming with Java 03 - Introduction to Classes and Objects.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 8: Classes and Objects.
OOP Basics Classes & Methods (c) IDMS/SQL News
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Lecture 9: Object and Classes Michael Hsu CSULA. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Object-Oriented programming for Beginners LEAPS Computing 2015
GC211 Data structure Lecture 3 Sara Alhajjam.
Lecture 3: Introduction to Object and Classes
Concepts of Object Oriented Programming
Objects as a programming concept
Examples of Classes & Objects
AKA the birth, life, and death of variables.
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
Classes and OOP.
Objects as a programming concept
Yanal Alahmad Java Workshop Yanal Alahmad
CS1201: Programming Language 2
OBJECT ORIENTED CONCEPTS
Methods.
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
Object Oriented Analysis and Design
Java LESSON 7 Objects, Part 1
Unit-2 Objects and Classes
Corresponds with Chapter 7
Building Java Programs
Classes & Objects: Examples
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Chapter 8 Objects and Classes Part 1
Building Java Programs
CS2011 Introduction to Programming I Objects and Classes
Chapter 8 Objects and Classes
AKA the birth, life, and death of variables.
Objects and Classes Creating Objects and Object Reference Variables
Basics of OOP A class is the blueprint of an object.
Outline Anatomy of a Class Encapsulation Anatomy of a Method
Scope of variables class scopeofvars {
Java Basics II Minseok Kwon
Object-Oriented Programming and class Design
CS1201: Programming Language 2
Chapter 8 Objects and Classes
Introduction to Object-Oriented Programming
Object-Oriented Programming and class Design
Chapter 9 Objects and Classes Part 01
Dr. R Z Khan Handout-3 Classes
OO Programming Concepts
Object-Oriented Programming and class Design
Introduction to Computer Science and Object-Oriented Programming
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Introduction to Programming G50PRO University of Nottingham Unit 9 : Classes and objects Paul Tennent http://paultennent.wordpress.com/G50PRO.html Paul.tennent@nottingham.ac.uk Room C7

Overview A more close look on classes and objects A brief introduction to object-oriented programming in java

What Is a Class? A building unit of a java program Your program may consist of multiple classes i.e.: you have been using the UserInput and String classes in many of your programs In object oriented programming a class is a blueprint or prototype from which objects are created.

Class Circle Example A class have three basic section Fields : which represent any variables that will represent the object state Constructors: one or more constructor used to initialise an object on creation Methods: which should provide any functionality (behaviour) required by the object

Class Circle Example public class Circle { //class fields private int x, y; private double radius; //constructors public Circle() { x = 0; y = 0; radius = 0; } public Circle (int ax, int ay, double aradius ) { x = ax; y = ay; radius = aradius;

Cont. Class Circle Example //methods public void move(int newx, int newy){ x = newx; y = newy; } public void resize(double newRadius){ radius = newRadius; public void print(){ System.out.println("x:"+ x +" y:"+ y +" \nradius:"+ radius); } // end of class

What Is an Object? Java is object oriented programming language Objects are key to understanding object-oriented technology real-world objects: television set, bicycle, car. objects have state and behavior

Using a Circle object A circle object is an instance of the circle class with an actual state We can change the state of the object using the offered methods //private fields x = 10 y = 15 radius = 2.5 move() print() resize() Methods (behavior)

Using a Circle object public class CircleDemo { public static void main (String[] args){ System.out.println ("Circle 1"); Circle c1 = new Circle(); c1.print(); c1.move(2,2); c1.resize(3); System.out.println ("\n Circle 2"); Circle c2 = new Circle(5,7,2.5); c2.print() } // end of main }// end of class

Key points: new : is a java key word that is used to create an instance of a class with a specific state Using : Circle c1 = new Circle(); will: Call the Circle class constructor The constructor will initialize the Circle class fields (assign state to the object) c1 is a reference variable, it holds a reference that points to a circle object in memory We may use c1 to access any public fields / methods of the class

More on OOP in java object-oriented programming (OOP) is a programming paradigm that make use of "objects" to design applications and computer programs It is commonly used in mainstream software application development since the early 1990s A more detailed study of OOP is out of the scope of this course, for more details: http://java.sun.com/docs/books/tutorial/java/concepts/index.html