Week 4 Recap CSE 115 Spring 2007. Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

This is Java Jeopardy Writing Methods…chapter 4…
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
COMP 121 Week 2: Interfaces and Polymorphism. Objectives To learn about interfaces To be able to convert between class and interface references To understand.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
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 2 Basics of C#. Members of a Class A field is a variable of any type that is declared directly in a class. Fields are members of their containing.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Association relationship We’ve seen one implementation of “knows a”: public class Dog.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Reminder Check the course web site on a regular basis:
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
CSE 115 Week 5 February , Monday Announcements Exam 3 today Exam 3 today Lab 3 due this week Lab 3 due this week Exam 4 Monday 2/18 Exam.
CS 106 Introduction to Computer Science I 11 / 20 / 2006 Instructor: Michael Eckmann.
Week 7 Recap CSE 115 Spring Not a Holder, but a Proxy be We actually wanted to build a Proxy for our program What is the difference? Holder is a.
Week 2 Recap CSE 115 – Spring Object Oriented Program System of objects that communicate with one another to solve some problem.
Week 6 Recap CSE 115 Spring Review We have built a program that uses Association, Composition, Instantiation Dependency, Local Instance Dependency,
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
Week 4 Recap CSE 115 Fall 2006 Section C. Decoupling Separation of concerns Defining what an object can do, not how it does it.
Java Syntax, Java Conventions, CSE 115 Conventions (Part 2) CSE 115 Spring 2006 January 30, February 1 & 3, 2006.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Association Also called “knows a”. A relationship of knowing (e.g. Dog-Collar as opposed to Dog-Tail)
Week 5 Recap CSE 115 Spring Composition Informally called “has a” Represented in UML with a diamond- headed arc In code: Declare an instance variable.
CSE 115 Week 3 January 28 – February 1, Monday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation.
CSE 115 Week 4 February 4 - 8, Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday.
Week 3 Recap CSE 115 – Spring Constructor Special capability of a class that sets up the initial state of the object. Constructor definitions are.
Week 3 Recap CSE 115 – Fall Java Source Code File Made up of: Package declaration Class definition.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
Multiple Choice Solutions True/False a c b e d   T F.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Classes CS 21a: Introduction to Computing I First Semester,
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
ECE122 Feb. 22, Any question on Vehicle sample code?
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
Chapter 10 Classes and Objects In-Depth. Chapter 10 A class provides the foundation for creating specific objects, each of which shares the general attributes,
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Objects and Classes.
Introduction to Object-Oriented Programming Lesson 2.
CSI 3125, Preliminaries, page 1 Class. CSI 3125, Preliminaries, page 2 Class The most important thing to understand about a class is that it defines a.
Side effects A side effect is anything that happens in a method other than computing and/or returning a value. Example: public class hello { public int.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-1 Learning Objectives  Classes  Constructors  Principles of OOP  Class type member.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
Chapter 5: Enhancing Classes
3 Introduction to Classes and Objects.
Wrapper Classes ints, doubles, and chars are known as primitive types, or built-in types. There are no methods associated with these types of variables.
Chapter 3 Introduction to Classes, Objects Methods and Strings
6 Delegate and Lambda Expressions
Unit-1 Introduction to Java
Classes, Encapsulation, Methods and Constructors (Continued)
CSE 115 September 29 – October 3, 2008.
Learning Objectives Classes Constructors Principles of OOP
CSE 115 September 29 – October 3, 2008.
Notes from Week 5 CSE 115 Spring 2006 February 13, 15 & 17, 2006.
Classes CS 21a: Introduction to Computing I
2009 Test Key.
Presentation transcript:

Week 4 Recap CSE 115 Spring 2007

Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the parameter followed by a name (type1 name1, type2 name2, type3 name3…)

Calling methods To get the actions of a method to be performed, we need to call (or invoke) the methods Methods are called on objects  How do we get an object?

Method calls object.methodToBeCalled() Recall the dot (.) operator [or member access operator] Notice the () here – this is an actual parameter list. If the method needs a parameter, we need to give an actual value to the method when we call it.

Important Note Two methods in Java can not have the exact same method header.

Implementing an Interface A class realizes an interface using the keyword implements. The formal name for this relationship is realization and the informal name is “implements” or “implements an interface” Inside the code, the class must create methods with the same signatures as those in the interface and give each method a method body.

Java Code: Implementing an Interface public class name implements InterfaceName { public void method1() { } public Object method2() { return null; } public void method3(Object obj) { } //Note that each method must have a method body, //but that method body could be empty. }

“Naming” our instances Sometimes we need a way to refer to an instance after we have created it. We can use a variable (reference) to communicate with an object.

Creating an instance variable Instance variables are the way we represent properties in our classes. Instance variables are only accessible inside the class body because we declare them to be private. Syntax for declaring an instance variable: private type identifier

Syntax of an instance variable (continued) Type: We must tell what type of thing the variable will refer to. Remember that our types are names of classes or interfaces. Identifier: Instance variable names follow the style conventions of a method, but are preceded by an underscore.

Assignment to a variable The = is the assignment operator It is right associative, that means the value on the right is assigned to the variable on the left. _variableName = new ObjectCreated();

Composition Relationship We have actually created the composition relationship. More on this relationship to come.