Huron High School AP Computer Science Instructor: Kevin Behemer S. Teacher: Guillermo Moreno.

Slides:



Advertisements
Similar presentations
COP 3330 : EXAM 1 REVIEW Page 1 © Dr. Mark Llewellyn COP 3330: Object-Oriented Programming Summer 2011 EXAM #1 – In Class Practice Department of Electrical.
Advertisements

Constructors & An Introduction to Methods. Defining Constructor – Car Example Public class car { String Model; double speed; String colour; { Public Car.
Inheritance and Polymorphism Recitation – 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University.
CS180 Chapter 4 2/1/08. Announcements Project 3 is out –2 weeks due to the exam Exam –Thursday, February 7, 8:30 – 9:30 pm, WTHR 104 –Covers chapters.
Huron High School AP Computer Science Instructor: Kevin Behmer S. Teacher: Guillermo Moreno.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Methods and Constructors reading: self-checks: #1-12.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors reading:
Packages. Package A package is a set of related classes Syntax to put a class into a package: package ; public class { …} Two rules:  A package declaration.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Based on slides at buildingjavaprograms.com Objects and Classes, take 2 Managing Complexity with Programmer-Defined Types  Classes are programmer-defined.
Static Keyword. What is static The static keyword is used when a member variable of a class has to be shared between all the instances of the class. All.
ICS 201 Introduction to Computer Science Problem Solving #4.
1 Software Construction Lab 4 Classes and Objects in Java Basics of Classes in Java.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, this reading: self-checks: #13-17 exercises:
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors, Encapsulation, this reading:
1 Object state: fields. Fields field: A variable inside an object that represents part of its internal state.  Each object will have its own copy of.
CSC 142 Computer Science II Zhen Jiang West Chester University
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Objects and Classes Mostafa Abdallah
CS305j Introduction to Computing Classes 1 Topic 23 Classes – Part I "A 'class' is where we teach an 'object' to behave." -Rich Pattis Based on slides.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
CSI 3125, Preliminaries, page 1 Compiling the Program.
CLASSES AND OBJECTS Object-Oriented Basics. Vocabulary Review – C++ Class Object Instance this new Constructor Default constructor Access (private/public/protected)
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 8: Classes and Objects.
Computer Programming 2 Lab (1) I.Fatimah Alzahrani.
Attribute - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 12/24/2016.
Classes - Intermediate
Object Oriented Programming I ( ) Dr. Adel hamdan Part 03 (Week 4) Dr. Adel Hamdan Date Created: 7/10/2011.
Methods.
1 Classes: A class is a concept of something Vehicle 4 wheels, seats, engine, windows, color…… accelerate, start, stop, turn, … attributes.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Parameter Passing in Java.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Invoking methods in the Java library. Jargon: method invocation Terminology: Invoking a method = executing a method Other phrases with exactly the same.
INHERITANCE -This feature allows one class to specialize the state and behavior of another class. -Significant code reuse can be achieved by this technique.
Review – Primitive Data What is primitive data? What are 3 examples of primitive data types? How is a piece of primitive data different from an object?
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Constructors; Encapsulation reading: self-checks: #13-18,
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors, Encapsulation, this reading:
J AVA P ROGRAMMING 2 CH 04: C LASSES, O BJECTS AND M ETHODS (II) 0.
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
CSC240 Computer Science III
Writing Methods.
CSC 113 Tutorial QUIZ I.
Building Java Programs
Building Java Programs
Building Java Programs
Unit-2 Objects and Classes
Building Java Programs
S.VIGNESH Assistant Professor, SECE
Classes Lecture 7 from Chapter /1/11.
JAVA Constructors.
class PrintOnetoTen { public static void main(String args[]) {
Building Java Programs
Building Java Programs
CSE 142 Lecture Notes Defining New Types of Objects, cont'd.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Unit-2 Objects and Classes
Building Java Programs
Overloading Each method has a signature: its name together with the number and types of its parameters Methods Signatures String toString()
class Box { double width; double height; double depth; }
Presentation transcript:

Huron High School AP Computer Science Instructor: Kevin Behemer S. Teacher: Guillermo Moreno

The this keyword The this keyword refers to the object that is currently executing. It is useful for a method to reference instance variables relative to this.

Example: this.varName varName is the name of an instance variable.

Another use: Allows one constructor to explicitly invoke another constructor in the same class. this ( args );

args is an optional set of arguments that maybe passed to a constructor. Only use this syntax as the first line in a constructor.

Class Point3D { double x; double y; double z; Point3D(double x, double y, double z) { this.x = x; this.y = y; this.z = z; }//end of constructor }//end of class Point3D

Class ThisKeywordDemo { public static void main(String args[]) { Point3D p = new Point3D(1.1, 3.4, -2.8); System.out.println(“p.x = “ + p.x); System.out.println(“p.y = “ + p.y); System.out.println(“p.z = “ + p.z); }//end of main function }//end of class ThisKeywordDemo

Output: p.x = 1.1 p.y = 3.4 p.z = -2.8