ECE122 Feb. 22, 2005. Any question on Vehicle sample code?

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

F UNCTION O VERLOADING Chapter 5 Department of CSE, BUET 1.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
1 Classes, Encapsulation, Methods and Constructors (Continued) Class definitions Instance data Encapsulation and Java modifiers Method declaration and.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
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)
Road Map Introduction to object oriented programming. Classes
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Constructors A constructor is a method that creates an object in Java. It does not return anything and it is not void. It’s only purpose is to create an.
Dale Roberts Object Oriented Programming using Java - Class Constructors Dale Roberts, Lecturer Computer Science, IUPUI Department.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
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.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
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.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
Methods: A Deeper Look. Template for Class Definition public class { } A.Import Statement B.Class Comments C.Class Name D.Data members E.Methods (inc.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Method Overloading  Methods of the same name can be declared in the same class for different sets of parameters  As the number, types and order of the.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
Class and Structure. 2 Structure Declare using the keyword struct purpose is to group data Default visibility mode is public A struct doesn't have a constructor.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
CIS 234: Java Methods Dr. Ralph D. Westfall April, 2010.
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.
Methods Methods are how we implement actions – actions that objects can do, or actions that can be done to objects. In Alice, we have methods such as move,
Lecture 5 functions 1 © by Pearson Education, Inc. All Rights Reserved.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 1.
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Java Programming, Second Edition Chapter Three Using Methods, Classes, and Objects.
CLASS AND OBJECTS Valerie Chu, Ph.D. LeMoyne-Owen College 1.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
Classes - Intermediate
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Methods.
Topics Instance variables, set and get methods Encapsulation
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Methods, classes, and Objects Dr. Jim Burns. Question  Which of the following access modifiers is the default modifier?  public  private  protected.
Review What is an object? What is a class?
Haidong Xue Summer 2011, at GSU
Java Primer 1: Types, Classes and Operators
Chapter 3: Using Methods, Classes, and Objects
Road Map Introduction to object oriented programming. Classes
Using local variable without initialization is an error.
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Chapter 3 Introduction to Classes, Objects Methods and Strings
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Classes & Objects: Examples
Classes, Encapsulation, Methods and Constructors (Continued)
JAVA Constructors.
CS2011 Introduction to Programming I Methods (I)
Class.
Java Programming Language
Functions Imran Rashid CTO at ManiWeber Technologies.
Chapter 4 Constructors Section 4.4
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
Constructors & Destructors
Corresponds with Chapter 5
Creating and Using Classes
Chapter 5 Classes.
Chapter 4 Test Review First day
Presentation transcript:

ECE122 Feb. 22, 2005

Any question on Vehicle sample code?

Returning from a method (review) void methods do not return a value to the method caller. Such method will return when its method closing brace is reached, or a return statement is executed. Methods that return with a value will return to the calling routine using this form of return: return value; //value is a variable of return data type //defined in method signature.

More on arguments & Parameters At the time of method call, the argument value in the call is assigned to the corresponding parameters in the method header. Compilation errors will occur if -- the number of arguments in a method call doesn’t match the number of parameters in the method declaration. -- the type of the arguments in a method call are not consistent with the types of the corresponding parameters in the method declaration.

Constructor We use “new” operator to create an object. What method is actually called really? Constructor is called!

What is a constructor It is a method of that class. Its method name is the same as the class name. It is usually declared public. It can have parameter list, or no parameter at all. It doesn’t have a return type. Within a constructor, data members can be initialized. If there is no constructor defined for a class, the compiler will create a default one(with no parameter) for you. Instance variables will be initialized to their default values, if you don’t assign one. A numeric value is initialized to zero, booleans are initialized to false, and a reference type is initialized to null. If you declare a constructor with parameters, the compiler will NOT create a default constructor for you. If you need a constructor without parameter, you have to create it yourself.

Constructor Overloading Overloaded constructor means you have more than one constructor in your class. Overloaded constructors must have different argument lists. You cannot have two constructors with the same arguments lists. An argument list includes the number, order and/or type of arguments.

Constructor example public class Constructor { int i; public Constructor() //constructor with no parameters { i = 100; //data member initialization } public Constructor(int j) //constructor with parameters { i = j; //initialization. }

Constructor example Instantiate a new object using constructor without parameter list, Constructor c = new Constructor(); Instantiate a new object using constructor with a parameter, Constructor d = new Constructor(50);

Assignments Practice and understand Constructor.java.