Introduction to Objects & Classes

Slides:



Advertisements
Similar presentations
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Advertisements

***** SWTJC STEM ***** Chapter 4-1 cg 42 Object Oriented Program Terms Up until now we have focused on application programs written in procedural oriented.
Road Map Introduction to object oriented programming. Classes
Const Parameters & In Line Functions 04/15/11. Next Time  Quiz, Monday, 04/18/11  Over 5.2 and 5.3 void functions pass-by-reference  Read 7.1 about.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
1 Objects and Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in Objects Reading for this Lecture:
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
UML Basics & Access Modifier
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
Week 3: Classes, constructors, destructors, new operator Operator and function overloading.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Chapter 3 Introduction to Classes and Objects Definitions Examples.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Class Everything in Java is in a class. The class has a constructor that creates the object. If you do not supply a constructor Java will create a default.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
Class Definitions and Writing Methods Chapter 3 3/31/16 & 4/4/16.
Class Definitions and Writing Methods Chapter 3 10/12/15 & 10/13/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education.
Class Definitions: The Fundamentals Chapter 6 3/30/15 & 4/2/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education.
INTRODUCTION Java is a true OO language the underlying structure of all Java programs is classes. Everything must be encapsulated in a class that defines.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
CS16: UML’s Unified Modeling Language. UML Class Diagram A UML class diagram is a graphical tool that can aid in the design of a class. The diagram has.
Andrew(amwallis) Classes!
Classes and Objects Introduced
Creating Your Own Classes
Program: Shape Area Print the area for various shape types using the respective formulas.
Creating Your OwnClasses
Anatomy of a class Part I
Lecture 9 Concepts of Programming Languages
Can perform actions and provide communication
Can perform actions and provide communication
Corresponds with Chapter 7
An Introduction to Java – Part II
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Implementing Classes Chapter 3.
The Object-Oriented Thought Process Chapter 04
Can perform actions and provide communication
Chapter 8 Objects and Classes
Objects and Classes Creating Objects and Object Reference Variables
Basics of OOP A class is the blueprint of an object.
JAVA An Introduction to Java OOP Basics
Java Basics II Minseok Kwon
Object-Oriented Programming
Chapter 14 Abstract Classes and Interfaces
Object-Oriented Programming and class Design
Chapter 8 Objects and Classes
Object-Oriented Programming and class Design
Chapter 9 Objects and Classes Part 01
Classes and Objects CGS3416 Spring 2019.
Code examples MakingCircles.java Circle.java Loopy.java
Lecture 8 Object Oriented Programming (OOP)
Object-Oriented Programming and class Design
Anatomy of a class Part I
(4 – 2) Introduction to Classes in C++
Chapter 7 Objects and Classes
CSG2H3 Object Oriented Programming
Lecture 9 Concepts of Programming Languages
Chengyu Sun California State University, Los Angeles
Object-Oriented Design AND CLASS PROPERTIES
Presentation transcript:

Introduction to Objects & Classes Paul Bui

Introduction Group related information and methods (functions) together Design classes with attributes and behaviors in mind Circle Example Attributes? Behaviors?

Building a Class - Attributes Name the java file the same name as the class (e.g. Circle.java) Capitalize the class name Put the attributes at the top of the class and make them private It’s nice to give them default values too (e.g. radius = 0.0) public class Circle { private double radius = 0.0; ... }

Building a Class - Constructors Used when the object is instantiated String str = new String(); No return type Always has the same name as the class Can have 0 or more parameters Two types:“default constructor” and “specific constructors” Example: public Circle() // “default constructor” has 0 parameters { }

Building a Class - Constructors “specific constructor” takes parameters that set the attributes Example: public Circle(double newRadius) { radius = newRadius; }

Building a Class - Methods Methods are defined and declared using the following template: public RETURNTYPE METHODNAME(PARAMETERS) { //METHOD CODE } Example: public double getArea() return 3.1415*radius*radius;

Naming Methods Naming Methods Parts of a method Capitalize every word in the method name EXCEPT for the first Example: thisIsAGoodMethodName() No spaces in the method name Parts of a method All methods except for the constructors have the same form RETURNTYPE METHODNAME ( PARAMETERS )

Methods – Getters & Setters Accessors (Getters) Used to access attributes 0 parameters Example public double getRadius() { return radius; }

Methods – Getters & Setters Mutators (Setters) Used to change attributes Most of the time has a return type of void Example public void setRadius(double newRadius) { radius = newRadius; }

Access Levels Controls whether or not the attribute or method can be seen/used outside of the class public, private, protected Put in front of class name, attributes, and methods