Lecture 8: Objects and Classes, cont’d discuss hw2 assign h3 Review the main points of objects/classes This Pass-by-value A new example: our Date class.

Slides:



Advertisements
Similar presentations
JAVA Revision Lecture Electronic Voting System Marina De Vos.
Advertisements

1 Lecture 16/3/11: Contents Example of an array of user-defined objects: Car and Carr Constructor Providing functionalities for a user- defined object.
Looking inside classes Fields, Constructors & Methods Week 3.
Lecture 9: More on objects, classes, strings discuss hw3 assign hw4 default values for variables scope of variables and shadowing null reference and NullPointerException.
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
Variable types We have already encountered the idea of a variable type. It is also possible to think about variables in terms of their kind, namely: 1)
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 13: Pass-by-Value?!?
Overloaded Constructors constructors can be overloaded, like other methods – i.e., a class can define several constructors all constructors must have the.
Lecture 10: Inheritance Subclasses and superclasses The inheritance chain Access control The Object cosmic superclass The super keyword Overriding methods.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 9: Pass-by-Value.
Lecture 5: Objects and Classes, cont’d Continue with the Player example Introduce GOAL as a final static variable that applies to all objects of the class.
1 More on Classes Overview l Overloading l The this keyword l The toString method l The equals method.
Understanding class definitions Looking inside classes.
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.
©2004 Brooks/Cole Chapter 10 More on Classes. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object assignment With primitive types, setting.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Programming Languages and Paradigms Object-Oriented Programming.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Lecture # 8 Constructors Overloading. Topics We will discuss the following main topics: – Static Class Members – Overloaded Methods – Overloaded Constructors.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
1 CSC103: Introduction to Computer and Programming Lecture No 14.
C# D1 CSC 298 Elements of C# code (part 2). C# D2 Writing a class (or a struct)  Similarly to Java or C++  Fields: to hold the class data  Methods:
Web Database Programming Week 3 PHP (2). Functions Group related statements together to serve “a” specific purpose –Avoid duplicated code –Easy maintenance.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Classes Java and other Object-Orientated Programs or OOP are based on the creation and interaction of classes. Every program in Java has at least one class.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Constructors & Garbage Collection Ch. 9 – Head First Java.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
1  lecture slides online
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
COMP 121 Week 8: Generic Collections. Objectives To understand type variables and how they are used in generic programming To be able to implement and.
From C++ to C# Part 5. Enums Similar to C++ Similar to C++ Read up section 1.10 of Spec. Read up section 1.10 of Spec.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Chapter 4Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapters 4 and 5: Excerpts l Class and Method Definitions l Information.
CS 100Lecture 111 CS100J Lecture 11 n Previous Lecture –Scope of names and the lifetime of variables n blocks and local variables n methods and parameters.
Today’s lecture Review chapter 5 go over exercises.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
Methods.
Methods main concepts – method call – object 's methods – actual parameters – method declaration – formal parameters – return value other concepts – method.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Parameter Passing in Java.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
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.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
Lecture 9: Object and Classes Michael Hsu CSULA. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object.
Introduction to Enumerations CMSC 202. Enumerated Values Enumerated values are used to represent a set of named values. Historically in Java (and other.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
The Object-Oriented Thought Process Chapter 03
Objects as a programming concept
Chapter 7: User-Defined Functions II
Haidong Xue Summer 2011, at GSU
Java Primer 1: Types, Classes and Operators
Agenda Warmup AP Exam Review: Litvin A2
Lecture 4 D&D Chapter 5 Methods including scope and overloading Date.
Using local variable without initialization is an error.
More Object Oriented Programming
Building Java Programs
Which best describes the relationship between classes and objects?
Handout-4b More on Classes
Java Programming Language
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Creating and Using Classes
Presentation transcript:

Lecture 8: Objects and Classes, cont’d discuss hw2 assign h3 Review the main points of objects/classes This Pass-by-value A new example: our Date class

HW2 Key point: main program constructs an array of Number objects Then the main program processes the array, typically several times, printing out all the numbers in bases of the user’s choice There is no array inside the Number class If you were confused on this point you can resubmit for a better grade

HW3 Placing queens on a chessboard

Classes serve 2 purposes A way of organizing static methods, e.g. the Math class Factories for constructing objects, which can then be processed by calling instance methods

This a way of referring to data fields (instance variables) of the object (can be omitted unless there is an ambiguity) a way of calling a constructor from another constructor with a different signature (the only way to do this?) a way of calling an instance method from another instance method (the only way to do this?) Only the first 2 of these are mentioned on p.236 Example: the Player class again

Java is a Pass-By-Value Language When a method is called, the values of the actual parameters are passed from the calling method to the called method It is not possible for the called method to pass changes to the actual parameters back to the calling method This applies whether the actual parameter is a primitive type or an object reference HOWEVER, if the actual parameter is an object reference, the called method CAN and often DOES change fields in the object that the reference points to