 Setter methods ◦ public methods that set the value of instance variables to a value specified by the call to the argument ◦ Setter methods do not violate.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Chapter 5 Part 1 COSI 11a Prepared by Ross Shaull.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
Methods CSC 171 FALL 2004 LECTURE 3. Methods Variables describe static aspects – “nouns” Methods describe dynamic aspects – “verbs”, “behaviors” – Methods.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
UML Basics & Access Modifier
Encapsulation CMSC 202. Types of Programmers Class programmers – Developers of new classes – Goal: Expose the minimum interface necessary to use a new.
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
Programming Progamz pls. Importance VERY IMPORTANT.
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!
Classes All Java code must be inside classes Class types – Utility classes Used to store constants, utility methods, etc. – Driver classes – Abstract Data.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 02 – Classes, Objects, Instances Richard Salomon and Umesh Patel Centre.
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Exercise 2 Introduction to C# CIS Create a class called Employee that contains the following private instance variables: Social Securitystring.
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.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Catie Welsh February 23,  Lab 4 due on Friday  Lab 5 will be assigned on Friday 2.
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
Methods.
Classes CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
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.
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.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Outline Anatomy of a Class Encapsulation Anatomy of a Method Copyright © 2014 Pearson Education, Inc.
Comp1004: Building Better Objects II Encapsulation and Constructors.
Testing It is much better to have a plan when testing your programs than it is to just randomly try values in a haphazard fashion. Testing Strategies:
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Staples are our staple Building upon our solution.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Examples of Classes & Objects
Arrays 3/4 By Pius Nyaanga.
using System; namespace Demo01 { class Program
Object Oriented Programming
HKCT Java OOP Unit 02 Object Oriented Programming in Java Unit 02 Methods, Classes, and Objects 1.
Java LESSON 7 Objects, Part 1
המשך תכנות מונחה עצמים תרגול מס' 9.
CSC 113 Tutorial QUIZ I.
Defining Your Own Classes Part 1
Stack Memory 2 (also called Call Stack)
Classes & Objects: Examples
Encapsulation and Constructors
CS 302 Week 9 Jim Williams.
Code Animation Examples
Example with Static Variable
CS2011 Introduction to Programming I Arrays (II)
Recursive GCD Demo public class Euclid {
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Basics of OOP A class is the blueprint of an object.
Object-Oriented Programming and class Design
Object-Oriented Programming and class Design
Agenda Warmup Lesson 2.2 (parameters, etc)
Arrays 3/4 June 3, 2019 ICS102: The course.
Chapter 6 Arrays.
Object-Oriented Design AND CLASS PROPERTIES
ITE “A” GROUP 2 ENCAPSULATION.
Object-Oriented Design AND CLASS PROPERTIES
CSG2H3 Object Oriented Programming
Presentation transcript:

 Setter methods ◦ public methods that set the value of instance variables to a value specified by the call to the argument ◦ Setter methods do not violate the idea of private data  you only change the variables you want ◦ Returns void (i.e. nothing)  Getter methods ◦ public method that displays value of private variables ◦ Again, does not violate idea of private data  You only display values you want to display ◦ Also called “accessor” or “query” methods  Other objects can treat the object as a black box

class carSetter { private String licensePlate; private int speed; void setlicensePlate(String plate) //setter method { licensePlate = plate; } void setspeed(int ispeed) //setter method { speed=ispeed; } }//end class

class carSetter { private String licensePlate; private int speed; void setlicensePlate(String plate) //setter method { licensePlate = plate; } void setspeed(int ispeed) //setter method { speed=ispeed; } String getlicensePlate() //getter method { return licensePlate; } int getspeed() //getter method { return speed; } }//end class

class getter_Example { public static void main(String args[]) { carSetter a = new carSetter(); a.setlicensePlate("02 C 14"); a.setspeed(10); System.out.println(a.getlicensePlate() + " is moving at " + a.getspeed() + " mph."); }//main }//