Classes and Objects CGS3416 Spring 2019.

Slides:



Advertisements
Similar presentations
Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
Advertisements

CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Association relationship We’ve seen one implementation of “knows a”: public class Dog.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Reminder Check the course web site on a regular basis:
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Lecture 9 Concepts of Programming Languages
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
More C++ Bryce Boe 2013/07/18 CS24, Summer 2013 C.
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
Chapter 10: Writing Class Definitions Visual Basic.NET Programming: From Problem Analysis to Program Design.
Week 3: Classes, constructors, destructors, new operator Operator and function overloading.
1 Chapter 3 and 6– Classes, Objects and Methods Object-Oriented Programming Concepts – Read it from Java TutorialJava Tutorial Definition: A class is a.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Mason Vail.  A data type definition – “blueprint for objects”  Includes properties and/or methods ◦ “instance” data / methods – specific to one object.
Object-Oriented PHP (Chapter 6).
1 Object-oriented design requires that we interact with a problem in much the same way that we interact with our world – we treat it as a set of separate.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
 Constructor  Finalize() method  this keyword  Method Overloading  Constructor Overloading  Object As an Argument  Returning Objects.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Classes Modeling the Object. Objects model the world Classes are programmer defined types that model the parts of a system Class serve as blueprints for.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Chapter 6 Classes & Objects. Learning Java through Alice 2 © Daly and Wrigley Class A class defines a particular kind of object. Each class is a blueprint.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
Topics Instance variables, set and get methods Encapsulation
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
Comp1004: Building Better Objects II Encapsulation and Constructors.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
OOP Details Constructors, copies, access. Initialize Fields are not initialized by default:
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Chapter 2 Objects and Classes
Written by: Dr. JJ Shepherd
OOP: Encapsulation &Abstraction
Classes (Part 1) Lecture 3
Classes C++ representation of an object
3 Introduction to Classes and Objects.
Agenda Warmup AP Exam Review: Litvin A2
Road Map Introduction to object oriented programming. Classes
Creating Your OwnClasses
Anatomy of a class Part I
Chapter 7 Classes & Objects.
Lecture 9 Concepts of Programming Languages
Encapsulation & Visibility Modifiers
Corresponds with Chapter 7
Defining Classes and Methods
Chapter 9 Classes & Objects.
Encapsulation and Constructors
Interfaces.
Chapter 7 Classes & Objects.
Java Inheritance.
Introduction to Objects & Classes
Object-Oriented Programming
Chapter 7 Classes & Objects.
CIS 199 Final Review.
Classes C++ representation of an object
Haidong Xue Summer 2011, at GSU
ITE “A” GROUP 2 ENCAPSULATION.
Anatomy of a class Part I
Creating and Using Classes
CSG2H3 Object Oriented Programming
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Classes and Objects CGS3416 Spring 2019

Classes Class is a blueprint for objects. A class is a user-defined type that describes and defines objects of the same type. A class contains data values and methods.

Data values

Objects and References

Objects

Creating an object from a class

References

Objects and References Object: an instance of a class Class: a template or blueprint from which individual objects are created Instantiation: the creation of an object class objName = new Constructor(); The constructor will always have the same name as the class Person sally = new Person();

Constructor A constructor is used to initialize an object (variables and call methods). Get objects of a class ready for use Same name as the class No return type

Type of constructor Default constructor Parameterized constructor

Method overloading Demo In Java it is possible to define two or more methods within the same class that are having the same name, but their parameter declarations are different. In the case, the methods are said to be overloaded, and the process is referred to as method overloading. Method overloading is one of the ways of java implementation of polymorphism. Demo

Constructors overloading vs Method overloading Strictly speaking, constructor overloading is somewhat similar to method overloading. If we want to have different ways of initializing an object using different number of parameters, then we must do constructor overloading as we do method overloading when we want different definitions of a method based on different parameters.

Constructor overloading Demo (Box and BoxRunner)

Protection levels in a class

Data Hiding

Demo (Student and StudentRunner)

Accessor and mutator methods Instance variables should be declared with the keyword private Data hiding is the main reason for the private declaration Accessor methods allow an outside class to READ instance variables Accessor methods often times start with the word get and can be called getters Mutator methods allow an outside class to WRITE instance variables Mutator methods often times start with the word set and can be called setters

Demo (Account and AccountRunner)

The ‘this’ keyword Many times it is necessary to refer to its own object in a method or a constructor. To allow this Java defines the ‘this’ keyword. The ‘this’ is used inside the method or constructor to refer its own object That is, ‘this’ is always a reference to the object of the current class type.