Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables Using this to override scope issues Lab: Creating a.

Slides:



Advertisements
Similar presentations
Section 6.1 CS 106, Fall The Big Q What do we get by being able to define a class?! Or Do we really need this?!
Advertisements

1 CSCE 1030 Computer Science 1 Introduction to Object Oriented Programming.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Lec 12 Writing an Instantiable Class. Agenda Review objects and classes Making our own class to create objects – Our first "Instantiable" class – with.
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
CSE 115/503 Introduction to Computer Science for Majors I1 Example Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); rover.setCollar(fido.getCollar());
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
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.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Copyright by Scott GrissomCh 1 Objects and Classes Slide 1 Classes and Objects A Class refers to something in general describes a category of items a cookie.
16/22/2015 2:54 PM6/22/2015 2:54 PM6/22/2015 2:54 PMObject-Oriented Development Concept originated with simulating objects and their interactions. Adapted.
Classes and Objects in Java
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
Week 3: Classes, constructors, destructors, new operator Operator and function overloading.
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.
1 Chapter 3 and 6– Classes, Objects and Methods Object-Oriented Programming Concepts – Read it from Java TutorialJava Tutorial Definition: A class is a.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Lec 13 Writing an Instantiable Class II. Agenda Adding to our Balloon Class demo: – default Constructor method – inflate method that takes a parameter.
Classes 1 COMPSCI 105 S Principles of Computer Science.
ECE122 Feb. 22, Any question on Vehicle sample code?
CS1201: Programming Language 2 Classes and objects By: Nouf Aljaffan Edited by : Nouf Almunyif.
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.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
SEEM3460 Tutorial Java Keyword – static. static Variables class XY { static int x; // class variable int y; // instance variable } XY xy1 = new XY();
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
CIS162AD Constructors Part 2 08_constructors.ppt.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Function PrototypetMyn1 Function Prototype We can declare a function before we use or define it by means of a function prototype. A function prototype.
Object and Classes อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 3.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Lab Demo 1 Dr. Mai Elshehaly.
Objects as a programming concept
Object-Oriented Programming
Chapter 7- Inheritance.
Interface, Subclass, and Abstract Class Review
Objects as a programming concept
University of Central Florida COP 3330 Object Oriented Programming
PHP Classes and Objects
CS Week 14 Jim Williams, PhD.
Using local variable without initialization is an error.
CS 302 Week 11 Jim Williams, PhD.
Enumerations & Annotations
Week 4 Object-based Programming (2) Classes and Objects: A Deeper Look
topics object oriented design objects and classes properties
Simple Classes in Java CSCI 392 Classes – Part 1.
Static is one of the modifiers that determine variable and method characteristics. The static modifier associates a variable or method with its class.
Lec 13 Writing an Instantiable Class II
Which best describes the relationship between classes and objects?
Session 2: Introduction to Object Oriented Programming
Chapter 14 Abstract Classes and Interfaces
Templates Generic Programming.
Topics OOP Review Inheritance Review Abstract Classes
Templates Generic Programming.
Lec 10 Using Objects II.
Day 11 The Last Week!.
Presentation transcript:

Lec 14 Writing an Instantiable Class III

Agenda Review of Instantiable Classes Scope of variables Using this to override scope issues Lab: Creating a Car class for a video game

Recall Structure of an Instantiable Class class Balloon size color Balloon inflate getSize getColor setColor pop Class Name Instance Varbls Methods Constructor method same name as class

Structure of an Instantiable Dog Class class Dog size Dog getSize setSize bark Class Name Instance Varbls Methods Constructor method same name as class

Now we'll begin ScopeThisDog Demo create Dog and MainApp classes show how scope errors can cause compile failure scope of – instance variables, parameters, and local variables Using keyword this to resolve scope issues in Class definition files

Scope errors in code below

Memory Map Dog fido = new Dog(30);

Lab14 You write a Car Class class Car double speed; int turnRate; Car getSpeed getTurnRate accelerate turnMoreLeft turnMoreRight Class Name Instance Varbls Methods Constructor method same name as class