3.1 Class Declaration

Size: px
Start display at page:

Download "3.1 Class Declaration"

Transcription

1 Chapter 3 Classes and Objects OBJECTIVES To be able to declare classes To understand object references To understand the mechanism of parameter passing To be able to use static member and instance member properly To become familiar with the organization of classes To understand the object life cycle and the scope of variables 3.1 Class Declaration Objects and classes are the bricks and mortar used to build Java programs. A class is a template for multiple objects with similar attributes and behaviors. An object-oriented program consists of classes from the static viewpoint and objects from the dynamic viewpoint. An instance of a class is another word for an actual object. If class is the abstract representation of an object, an instance is its concrete representation. We use the terms object and instance interchangeably. An object has a unique identity, state, and behaviors. The state of an object is represented by fields (also known as member variables) with their current values. The behavior of an object is defined by a set of methods. Invoking a method on an object means that you ask the object to perform a task. A Java class uses variables to define attributes and methods to define behaviors of an object. Additionally, a class provides methods of a special type, known as constructors, which are invoked when a new object is created. A constructor is a special kind of method and is designed to perform initializations. All the qualities of a class are specified in the class declaration, which consists of optional fields, optional methods, optional constructors, and optional member classes (inner classes). There are several kinds of variables in a class: member variables in a class these are also called fields; Variables in a method or block of code these are called local variables; Variables at the head of a method these are called parameters. Think of a car with attributes name, height, width and coordinate position. It can move ahead (measured in pixels) as well as move back (with a negative number of pixels). For the sake of simplicity, we suppose the car here can only turn left and turn right by 90 degrees, that is, either move in a counter-clockwise direction or a clockwise direction. Fig. 3.1 illustrates the model. 87

2 Code 3.1 Car.java package carrace; /** * The basic car class Donald. Dong (original) */ public class Car { public Car() { Fig. 3.1 The Car model name = "N/A"; public Car(String name) { this.name = name; /** * Immediately moves your car moveahead (forward) by distance measured * in pixels. * Example: * <pre> * //Move the car 100 pixels forward * moveahead(100); * * //Afterwards, move the car 50 pixels backward * moveahead(-50); * </pre> * distance the distance to move moveahead measured in pixels. * If this value is negative, the car will move backword instead of move forward. */ public void moveahead(int distance) { switch (direction) { case 0: y = y + distance; break; case 1: x = x + distance; break; case 2: y = y - distance; break; case 3: x = x - distance; break; 88

3 /** * Turn the car to another direction clockwise. */ public void turnright() { direction = (byte) ((direction + 1) % 4); /** * Turn the car to another direction counter-clockwise. */ public void turnleft() { direction = (byte) ((direction - 1) % 4); /** * Returns the height of the car measured in pixels. the height of the car measured in pixels. #getwidth() */ public double getheight() { return height; /** * Returns the width of the car measured in pixels. the width of the car measured in pixels. #getheight() */ public double getwidth() { return width; /** * Returns the car's name. the car's name. */ public String getname() { return name; /** * Returns the X position of the car. (0,0) is at the bottom left of the racecourse. the X position of the car. #gety() */ public double getx() { 89

4 return x; /** * Returns the Y position of the car. (0,0) is at the bottom left of the racecourse. the Y position of the car. #getx() */ public double gety() { return y; private String name; private double width = 40, height = 30; private int x = 400, y = 300; private byte direction = 0; //0: top; 1: right; 2: bottom; 3: left The components of the class code are depicted in Fig Fig. 3.2 The components of a class The member variables declare the attributes of a car such as its coordinate position (x, y) as an integer type. By default, the two variables will be initialized to 0 implicitly. How different member variables are initialized implicitly is shown in Table 3.1. Table 3.1 Default initial values Type byte short int long float double char boolean object Initial value L 0.0f 0.0d '\u0000' false null 90

5 The member variables will only be visible to, or in the scope of, all the methods in the class following the "private" modifier. A class declaration typically includes one or more member variables of various types. Member variables can use either the default values or explicit initialization. A class declaration typically includes one or more methods, which implement some behaviors. Methods resemble the functions in C language. A method will be called, or invoked, by some other methods. A method does not need to return a value. Such a method uses the void return type modifier as shown in the Car class(table 3.2). On the other hand, a method usually returns a value. Method public class Car{ public int getx (){ return x; public void setx (int i){ x = i; public boolean fire() { int i = 2; return (bullets - i < 0); private int x, y; private int bullets; Table 3.2 Methods in a class Comment A method to return the value of the x variable. A method to set the value of the x variable. The parameter i defines what kind of value is passed to the method. A variable declared in a method is a local variable. A local variable is valid only within the method. It must be assigned a value before it is used. The structure of a method includes a method head and a code body: <access_modifier> <return_type> <method_name> (<list_of_parameters>) { The method s name and the parameter types of a method declaration comprise the method signature. The method body, enclosed between braces, consists of the method s code and the declaration of local variables, as shown in Fig A constructor is called when an instance of this class is first created. It is used to initialize the member variables. The constructor signature looks similar to that of a regular method. It has a name that matches the class name and holds a list of parameters in parentheses. However, a constructor has no return type. Constructors are invoked using the new operator when an object is created. 91

6 Fig. 3.3 A method declaration public Car() { name = "N/A"; public Car(String name) { this.name = name; The code above shows two constructors with the class Car in code 3.1. If there is no constructor in a class declaration, the Java compiler will create a default constructor with an empty parameter list. For example, if there is no constructor is defined in the class Car, JVM will use the default parameterless constructor. The default constructor calls the default parent constructor (super()) and initializes all instance variables to default value (zero for numeric types, null for object references, and false for booleans). Once any constructor is defined in the class Car, there will be no constructor generated by the Java compiler. Code 3.2 shows that a compilation error occurs in the case when a constructor with parameters is defined while a constructor with an empty parameter list is invoked. Code 3.2 Test.java public class Test { public static void main(string[] args) { Car a = new Car(); //Compilation error //Car.java class Car { 92

7 public Car (String name) { this.name = name; String name; The Java compiler puts the initialization data for the member variable into the byte code for the constructor. So, for a class with several fields, the initialization of the default or explicit values occurs in the constructor. For example, Car1 and Car2 defined in Code 3.3 have the same effect in the client class Test after being created. Code 3.3 Test1.java and Test2.java class Car1 { public Car1() { width = 1.0; height = 2.0; private String name; private double width, height; private int x, y; public class Test1{ public static void main(string[] args) { Car1 a = new Car1(); class Car2 { private String name; private double width = 1.0, height = 2.0; private int x, y; public class Test2 { public static void main(string[] args) { Car2 a = new Car2(); Note that multiple constructors provide optional ways to create and initialize instances of the class. 93

8 3.2 Creating Objects A class is the template of objects. An object is created from a class. For example, Car a = new Car(1.0, 2.0); The Car class is already defined in Fig The expression new Car(1.0, 2.0) returns an object reference that refers to a Car object. Each of these statements has three parts: declaration, instantiation and initialization. Car a = new Car(1.0, 2.0); Declaration Instantiation Initialization Declaration means to associates a variable name with an object type. Instantiation implies to create the object with the new operator. A constructor is called to initialize the new object when the initialization performs. The phrase instantiating a class has the same meaning as creating an object. To create an object is to allocate memory space for the member variables of the object, execute the constructor and return the reference to the new object. The statement a = new Car(1.0, 2.0); can be read as: create an object of type Car and assign its reference to a. The memory assignments for the object created and its reference by the statement are visualized in Fig Fig. 3.4 The memory assignments by a = new Car(1.0, 2.0); 3.3 Accessing Objects via Reference Variables Once an object is created, it is ready to be used for something. For example, let a car move ahead: a.moveahead(7); The client code that is outside the object s class must use an object reference, followed by the dot (.) operator, followed by a method name, within enclosing parentheses and any arguments to the method. If the method does not require any arguments, use empty parentheses. As in <object_reference>. <method_name>(<arguments_list>) 94

9 or <object_reference>. <method_name>() The statement a.moveahead(7); sends the message moveahead with an argument of 7 to the object a. Sending a message to that object is the same as invoking a method on the particular object. Object member variables are accessed by their name within its own class. For example, there is a statement within the area() method that uses the width and height: public double area(){ double result = 0.0; result = width*height; return result; Code that is outside the object s class must use an object reference or expression, followed by the dot (.) operator, followed by a member variable name, as in <object_reference>.<member_variable_name> The client code Test uses two of these names to display the width and the height of a: System.out.println("Width of a: " + a.width); System.out.println("Height of a: " + a.height); Attempting to access width and height from the code in the Test class results in a compiler error since their private modifier indicates that this can only be visited inside the class Car. It will be successful if the modifier is changed to public. Details about access modifiers will be discussed later. 3.4 Object Reference this this is a reference to the current object which is the object whose method or constructor is being called. It refers to the newly created object in constructors, or refers to the object that a method belongs to in the method. For example, this is used to distinguish member variables from parameters in the constructor of the class Car declaration. public class Car { public Car(double width, double height) { this.width = width; this.height = height; 95

10 private double width, height; By this, a constructor can invoke another constructor: public class Car { public Car(double width, double height) { this.width = width; this.height = height; public Car() { this(0.0, 0.0); private double width, height; Note that this(0.0, 0.0); must be the first statement in the constructor in this case. public void setlocation(point p){ currentlocation = p; is equivalent to public void setlocation(point p){ this.currentlocation = p; and so is also in a method. 3.5 Parameter Passing The list of variables in a method head declaration are the parameters. The actual values that are passed when the method is invoked are called the arguments. When a method is invoked, the arguments must match the corresponding parameters in type and order. All the arguments are passed by value, that is, a copy of the argument is assigned to the corresponding parameter. The typical method call sequence is: 1. Evaluate arguments left-to-right. If an argument is a simple variable or a literal value, there is no need to evaluate it. When an expression is used, the expression must be evaluated before the call can be made. 2. When a method is called, a temporary piece of memory is required to store the following information: parameter and local variable storage, where to continue execution when the called method returns and any other working storage needed by the method. 96

11 3. Initialize the parameters. When the arguments are evaluated, they are assigned to the local parameters in the called method. 4. Execute the method. Execution starts with the first statement and continues as normal. 5. Return from the method. When a return statement is encountered, or the end of a void method is reached, the method returns. For non-void methods, the return value is passed back to the calling method. Execution is continued in the calling method immediately following where the call took place. Any data type can be used for a parameter of a method or a constructor. This includes primitive data types, such as doubles, floats, and integers, and reference data types, such as objects. Code 3.4 shows how to use primitive types or reference type as parameter types. Code 3.4 Car.java and Point.java public class Car { public Car() { this(0, 0); public Car(double width, double height) { this.width = width; this.height = height; public double area() { return width * height; public void setlocation(point p){ currentlocation = p; public void setlocation(int x, int y){ Point p = new Point(x, y); currentlocation = p; private double width, height; private Point currentlocation; //The current location of this object public class Point { public Point() { public Point(int xvalue, int yvalue) { x = xvalue; y = yvalue; //return x from coordinate pair public int getx() { 97

12 return x; //return y from coordinate pair public int gety() { return y; public void setxy(int x, int y) { this.x = x; this.y = y; public String tostring() { return "[" + getx() + ", " + gety() + "]"; private int x; //x part of coordinate pair private int y; //y part of coordinate pair The method setlocation is used to set the position of a car. The argument can be either a Point object reference or a coordinate pair. Java doesn t allow passing methods into methods. However, an object reference can be passed into a method and the object s methods can then be invoked. Any changes to the values of the parameters exist only within the scope of the method. When the method returns, the parameters disappear and any changes made to them are lost. In the case of reference type, the passed-in reference still references the same object as before when the method returns. However, the values of the object s fields can be changed in the method. Code 3.5 creates a car with the argument width 3 and the argument height 6. It then set its location to (10, 20). Code 3.5 ParaDemo.java public class ParaDemo { public static void main(string args[]) { Car a = new Car(3,6); a.setlocation(10, 20); 20). After invoking setlocation(10, 20), the parameter x holds 10 and y holds 20. Code 3.6 creates a car in which the width is 3 and the height is 6. It sets its location to (10, Code 3.6 ParaDemo.java public class ParaDemo { 98

13 public static void main(string args[]) { Car a = new Car(3, 6); Point apoint = new Point(10, 20); a.setlocation(apoint); Assume setlocation() is invoked as below. public void setlocation(point p){ currentlocation = p; Just before the statement currentlocation = p; executes, the parameter p holds exactly what apoint holds, which is the reference to the Point object created. The Point object still remains, i.e, no copy or clone is made. The states of the Point object and Car object are visualized in Fig Fig. 3.5 The memory assignments for the Point object and Car object before the statement currentlocation = p; After the call a.setlocation(apoint); control returns to the main method, public static void main(string args[]) { Car a = new Car(3,6); Point apoint = new Point(10,20); a.setlocation(apoint); The states of the objects are shown in Fig Observe that the parameter p has disappeared after the setlocation() method returns. However, the Car object a has changed: its field currentlocation refers to the new object created in main(). 99

14 Fig. 3.6 The memory assignments for the Point object and Car object After the call a.setlocation (apoint); This mechanism is known as pass-by-value. There are important differences between passing the values of primitive data types and passing objects: For an argument of a primitive type, the argument s value is passed. For an argument of a reference type, the value of the argument contains a reference to an object and this reference is passed to the method. The example below contains two methods for swapping elements in an array, which is an object. The first method, named swap, fails to swap two int arguments. The second method, named exchange, successfully swaps the first two elements in the array arguments. Code 3.7 does the job. Code 3.7 ArrayAsPara.java public class ArrayAsPara { public static void main(string[] args) { int[] a = {2,3; swap(a[0],a[1]); exchange(a); static void swap(int x, int y){ int temp = x; x = y; y = temp; static void exchange(int[] a){ int temp = a[0]; a[0] = a[1]; a[1] = temp; Fig. 3.7, Fig. 3.8, and Fig. 3.9 show the content of array a before invoking swap(), after invoking swap(), and after invoking exchange() respectively in the Eclipse debug view. It results the two elements of the array remaining unchanged after the execution of swap(a[0],a[1]); while they are exchanged after the execution of exchange(a). 100

15 Fig. 3.7 The content of the array a before invoking swap() Fig. 3.8 The content of the array a after invoking swap() 101

16 Fig. 3.9 The content of the array a after invoking exchange() 3.6 Returning from a Method A method returns in three ways: all the statements in the method are completed; a return statement is reached; or an exception is thrown. A return statement can be used to exit a method: return; If a method returns a value, the return statement contains a corresponding return value, like this: return <returnvalue>; Any method declared void doesn t return a value and it is unnecessary to contain a return statement in these methods. Any method that is not declared void must contain a return statement with a corresponding return value and the data type of the return value must match the method s declared return type. Code 3.8 demonstrates the return statement. Code 3.8 ReturnDemo.java public class ReturnDemo { public static void main(string[] args) { 102

17 A a = new A(); B b1 = a.getb(); b1.say(); class A { public B getb(){ B b= new B(); return b; class B{ public void say(){ System.out.println("I am B."); It displays I am B. 3.7 Method Overloading Java supports overloading methods, and it can distinguish between methods with different method signatures. That is, two or more methods within a class can have the same name if they have a different parameter list. Observe the method setlocation in Code 3.4: public void setlocation(point p){ currentlocation = p; public void setlocation(int x, int y){ Point p = new Point(x, y); currentlocation = p; This phenomenon is so-called method overloading. The PrintWriter class in Java provides many println methods using this technology: java.io.printwriter.println() java.io.printwriter.println(boolean) java.io.printwriter.println(char) java.io.printwriter.println(char[]) java.io.printwriter.println(double) java.io.printwriter.println(float) 103

18 java.io.printwriter.println(int) java.io.printwriter.println(java.lang.object) java.io.printwriter.println(java.lang.string) java.io.printwriter.println(long) 3.8 Class Variables and Instance Variables Any object has its own state. For example, Car a = new Car(1.0, 2.0); Car b = new Car(2.0, 2.0); The states of the object a and b are shown in Fig Fig The memory assignments for the object a and b Java does everything with objects. There are no global variables, for example, as in C/C++ that exist outside of the objects. To provide public resources visited by objects, Java offers static variables and methods that are contained in a class definition but exist and can be accessed without creating an instance of the class. A static variable or method is also called a class variable or method, since it belongs to the class itself rather than to an instance of that class. A variable is declared as static by the static modifier. The non-static member variables are referred to as instance variables since the values belong to a unique instance of the class. The instance variable has the same life cycle as the object it belongs to. Note that class methods can only refer to static members and to the parameter list. Code 3.9 shows car a notifying car b and c when a dog is detected ahead. Code 3.9 StaticViariableDemo.java public class StaticViariableDemo { public static void main(string args[]) { Car a = new Car(); Car b = new Car(); 104

19 Car c = new Car(); a.notify("a dog ahead!"); System.out.println("Car b: " + b.response()); System.out.println("Car c: " + c.response()); class Car { public Car() { this.width = 3; this.height = 4; public void notify(string note) { Car.note = note; public String response() { return Car.note; public static String note; //Message shared by the two Cars. double width, height; In this demonstration, car a noticed a dog ahead and notifies other cars b and c this message via invoking its method a.notify("a dog ahead!"). The method post this message on the static member variable note, which can be accessed by car b and c. Car b and c can get the message via their own method response(). We can access the static variables directly using the name of the class, as in Car.note="Dog!"; The general form is <class_name>.<static_variable> There are three ways to initialize instance variables: declaration, creation and invoking a method. 1. Declaration public class A { public void amethod() { private int amember = 1; //Instance variable that has a initial value 105

20 2. Constructor class A { A(int i) { amember = i; private int amember; //Instance the variable by a constructor 3. Method class A { void f() { amember = 0; //Instance the variable by a method int amember; Static variables cannot be initialized by constructors. Initialization can be done by declaration or a regular method. In summary, a static variable is a variable that belongs to the class and not to an object. A single copy is shared by all instances of the class. A static variable can be accessed directly by the class name and does not need any object. 3.9 Class Methods and Instance Methods There are two types of methods. One type is instance methods that are associated with an object and operate the instance variables of that object. This is the default. The other type is static methods that cannot use any instance variables of any object of the class they are defined in. The typical usage of static methods is to do some kind of generic calculation such as methods in Math and java.util.random. A method is declared as static by the static modifier. Static methods are invoked with the class name, without the need for creating an instance of the class, as in <class_name>.<method_name>(<argument_list>) Remember that an instance method is called by prefixing it with an object reference outside the defining class. The following static method converts a thermograph from degrees Centigrade to Fahrenheit. public class Thermograph{ public static int centigradetofahrenheit(int cent){ return cent * 9 / ; 106

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 21, 2013 Abstract

More information

CSE 142 Su 04 Computer Programming 1 - Java. Objects

CSE 142 Su 04 Computer Programming 1 - Java. Objects Objects Objects have state and behavior. State is maintained in instance variables which live as long as the object does. Behavior is implemented in methods, which can be called by other objects to request

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

CHAPTER 7 OBJECTS AND CLASSES

CHAPTER 7 OBJECTS AND CLASSES CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and

More information

CHAPTER 7 OBJECTS AND CLASSES

CHAPTER 7 OBJECTS AND CLASSES CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

For this section, we will implement a class with only non-static features, that represents a rectangle

For this section, we will implement a class with only non-static features, that represents a rectangle For this section, we will implement a class with only non-static features, that represents a rectangle 2 As in the last lecture, the class declaration starts by specifying the class name public class Rectangle

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

More information

COMP 250 Winter 2011 Reading: Java background January 5, 2011

COMP 250 Winter 2011 Reading: Java background January 5, 2011 Almost all of you have taken COMP 202 or equivalent, so I am assuming that you are familiar with the basic techniques and definitions of Java covered in that course. Those of you who have not taken a COMP

More information

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Covered in this chapter Classes Objects Methods Parameters double primitive type } Create a new class (GradeBook) } Use it to create an object.

More information

Declarations and Access Control SCJP tips

Declarations and Access Control  SCJP tips Declarations and Access Control www.techfaq360.com SCJP tips Write code that declares, constructs, and initializes arrays of any base type using any of the permitted forms both for declaration and for

More information

1. Class Relationships

1. Class Relationships 1. Class Relationships See also: Class declarations define new reference types and describe how they are implemented. Constructors are similar to methods, but cannot be invoked directly by a method call;

More information

Array. Prepared By - Rifat Shahriyar

Array. Prepared By - Rifat Shahriyar Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types

More information

Chapter 4 Defining Classes I

Chapter 4 Defining Classes I Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba Laboratory Session: Exercises on classes Analogy to help you understand classes and their contents. Suppose you want to drive a car and make it go faster by pressing down

More information

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and Classes CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

CS 251 Intermediate Programming Methods and More

CS 251 Intermediate Programming Methods and More CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

Defining Classes and Methods

Defining Classes and Methods Defining Classes and Methods Chapter 5 Modified by James O Reilly Class and Method Definitions OOP- Object Oriented Programming Big Ideas: Group data and related functions (methods) into Objects (Encapsulation)

More information

Class, Variable, Constructor, Object, Method Questions

Class, Variable, Constructor, Object, Method Questions Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx

More information

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours: CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Thursday 12:00 PM 2:00 PM Friday 8:30 AM 10:30 AM OR request appointment via e-mail

More information

Java Classes & Primitive Types

Java Classes & Primitive Types Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)

More information

Outline. Inheritance. Abstract Classes Interfaces. Class Extension Overriding Methods Inheritance and Constructors Polymorphism.

Outline. Inheritance. Abstract Classes Interfaces. Class Extension Overriding Methods Inheritance and Constructors Polymorphism. Outline Inheritance Class Extension Overriding Methods Inheritance and Constructors Polymorphism Abstract Classes Interfaces 1 OOP Principles Encapsulation Methods and data are combined in classes Not

More information

Assumptions. History

Assumptions. History Assumptions A Brief Introduction to Java for C++ Programmers: Part 1 ENGI 5895: Software Design Faculty of Engineering & Applied Science Memorial University of Newfoundland You already know C++ You understand

More information

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 02: Using Objects MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Using Objects 2 Introduction to Object Oriented Programming Paradigm Objects and References Memory Management

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3 Class A class is a template that specifies the attributes and behavior of things or objects. A class is a blueprint or prototype from which objects are created. A class is the implementation of an abstract

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Objects and Classes (1)

Objects and Classes (1) Objects and Classes (1) Reading: Classes (interface, implementation, garbage collection) http://moodle.cs.man.ac.uk/course/view.php?id=81 Interface Examples Creating and using objects of existing classes

More information

Introduction to Computer Science I

Introduction to Computer Science I Introduction to Computer Science I Classes Janyl Jumadinova 5-7 March, 2018 Classes Most of our previous programs all just had a main() method in one file. 2/13 Classes Most of our previous programs all

More information

Chapter 4. Defining Classes I

Chapter 4. Defining Classes I Chapter 4 Defining Classes I Introduction Classes are the most important language feature that make object oriented programming (OOP) possible Programming in Java consists of dfii defining a number of

More information

Constants are named in ALL_CAPS, using upper case letters and underscores in their names.

Constants are named in ALL_CAPS, using upper case letters and underscores in their names. Naming conventions in Java The method signature Invoking methods All class names are capitalized Variable names and method names start with a lower case letter, but every word in the name after the first

More information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

COE318 Lecture Notes Week 3 (Sept 19, 2011)

COE318 Lecture Notes Week 3 (Sept 19, 2011) COE318 Lecture Notes: Week 3 1 of 8 COE318 Lecture Notes Week 3 (Sept 19, 2011) Topics Announcements TurningRobot example PersonAge example Announcements The submit command now works. Quiz: Monday October

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1)

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1) Topics Data Structures and Information Systems Part 1: Data Structures Michele Zito Lecture 3: Arrays (1) Data structure definition: arrays. Java arrays creation access Primitive types and reference types

More information

Defining Classes and Methods. Objectives. Objectives 6/27/2014. Chapter 5

Defining Classes and Methods. Objectives. Objectives 6/27/2014. Chapter 5 Defining Classes and Methods Chapter 5 Objectives Describe concepts of class, class object Create class objects Define a Java class, its methods Describe use of parameters in a method Use modifiers public,

More information

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber Chapter 10 Inheritance and Polymorphism Dr. Hikmat Jaber 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the

More information

Programming Language Concepts: Lecture 2

Programming Language Concepts: Lecture 2 Programming Language Concepts: Lecture 2 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2011 PLC 2011, Lecture 2, 6 January 2011 Classes and

More information

Fundamental Concepts and Definitions

Fundamental Concepts and Definitions Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most

More information

Creating an object Instance variables

Creating an object Instance variables Introduction to Objects: Semantics and Syntax Defining i an object Creating an object Instance variables Instance methods What is OOP? Object-oriented programming (constructing software using objects)

More information

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017 Java Methods Lecture 8 COP 3252 Summer 2017 May 23, 2017 Java Methods In Java, the word method refers to the same kind of thing that the word function is used for in other languages. Specifically, a method

More information

CONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence.

CONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence. Constructor in Java 1. What are CONSTRUCTORs? Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs

More information

Methods. Methods. Mysteries Revealed

Methods. Methods. Mysteries Revealed Methods Methods and Data (Savitch, Chapter 5) TOPICS Invoking Methods Return Values Local Variables Method Parameters Public versus Private A method (a.k.a. func2on, procedure, rou2ne) is a piece of code

More information

An introduction to Java II

An introduction to Java II An introduction to Java II Bruce Eckel, Thinking in Java, 4th edition, PrenticeHall, New Jersey, cf. http://mindview.net/books/tij4 jvo@ualg.pt José Valente de Oliveira 4-1 Java: Generalities A little

More information

Classes as Blueprints: How to Define New Types of Objects

Classes as Blueprints: How to Define New Types of Objects Unit 5, Part 1 Classes as Blueprints: How to Define New Types of Objects Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Types of Decomposition When writing a program, it's important

More information

Module - 3 Classes, Inheritance, Exceptions, Packages and Interfaces. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Module - 3 Classes, Inheritance, Exceptions, Packages and Interfaces. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Module - 3 Classes, Inheritance, Exceptions, Packages and Interfaces OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani Introducing Classes A class defines a new data type (User defined data type). This

More information

Object Oriented Modeling

Object Oriented Modeling Object Oriented Modeling Object oriented modeling is a method that models the characteristics of real or abstract objects from application domain using classes and objects. Objects Software objects are

More information

9 Working with the Java Class Library

9 Working with the Java Class Library 9 Working with the Java Class Library 1 Objectives At the end of the lesson, the student should be able to: Explain object-oriented programming and some of its concepts Differentiate between classes and

More information

OBJECT ORİENTATİON ENCAPSULATİON

OBJECT ORİENTATİON ENCAPSULATİON OBJECT ORİENTATİON Software development can be seen as a modeling activity. The first step in the software development is the modeling of the problem we are trying to solve and building the conceptual

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 02: Using Objects MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Using Objects 2 Introduction to Object Oriented Programming Paradigm Objects and References Memory Management

More information

Operations. I Forgot 9/4/2016 COMPUTER SCIENCE DEPARTMENT PICNIC. If you forgot your IClicker, or your batteries fail during the exam

Operations. I Forgot 9/4/2016 COMPUTER SCIENCE DEPARTMENT PICNIC. If you forgot your IClicker, or your batteries fail during the exam COMPUTER SCIENCE DEPARTMENT PICNIC Welcome to the 2016-2017 Academic year! Meet your faculty, department staff, and fellow students in a social setting. Food and drink will be provided. When: Saturday,

More information

COMP 202. More on OO. CONTENTS: static revisited this reference class dependencies method parameters variable scope method overloading

COMP 202. More on OO. CONTENTS: static revisited this reference class dependencies method parameters variable scope method overloading COMP 202 CONTENTS: static revisited this reference class dependencies method parameters variable scope method overloading More on OO COMP 202 Objects 3 1 Static member variables So far: Member variables

More information

Lecture 13 & 14. Single Dimensional Arrays. Dr. Martin O Connor CA166

Lecture 13 & 14. Single Dimensional Arrays. Dr. Martin O Connor CA166 Lecture 13 & 14 Single Dimensional Arrays Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Table of Contents Declaring and Instantiating Arrays Accessing Array Elements Writing Methods that Process

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

Java Classes & Primitive Types

Java Classes & Primitive Types Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)

More information

More Java Basics. class Vector { Object[] myarray;... //insert x in the array void insert(object x) {...} Then we can use Vector to hold any objects.

More Java Basics. class Vector { Object[] myarray;... //insert x in the array void insert(object x) {...} Then we can use Vector to hold any objects. More Java Basics 1. INHERITANCE AND DYNAMIC TYPE-CASTING Java performs automatic type conversion from a sub-type to a super-type. That is, if a method requires a parameter of type A, we can call the method

More information

Unit 5: More on Classes/Objects Notes

Unit 5: More on Classes/Objects Notes Unit 5: More on Classes/Objects Notes AP CS A The Difference between Primitive and Object/Reference Data Types First, remember the definition of a variable. A variable is a. So, an obvious question is:

More information

McGill University School of Computer Science COMP-202A Introduction to Computing 1

McGill University School of Computer Science COMP-202A Introduction to Computing 1 McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif

More information

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Chapter 3 Classes & Objects

Chapter 3 Classes & Objects 1 Chapter 3 Classes & Objects Question 1: Given the code below, 1. public class Try 3. private static int sum = 20; 4. public static void main(string args[]) 5. { 6. Try t1 = new Try(); 7. Try.sum++; 8.

More information

CSC 102 Lecture Notes Week 2 Introduction to Incremental Development and Systematic Testing More Jav a Basics

CSC 102 Lecture Notes Week 2 Introduction to Incremental Development and Systematic Testing More Jav a Basics CSC103-S010-L2 Page 1 CSC 102 Lecture Notes Week 2 Introduction to Incremental Development and Systematic Testing More Jav a Basics Revised 12 April I. Relevant reading. A. Horstmann chapters 1-6 (continued

More information

Chapter 8 Objects and Classes. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Chapter 8 Objects and Classes. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. Chapter 8 Objects and Classes 1 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections, loops, methods, and arrays. However, these Java

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Dr. M. G. Abbas Malik Assistant Professor Faculty of Computing and IT (North Jeddah Branch) King Abdulaziz University, Jeddah, KSA mgmalik@kau.edu.sa www.sanlp.org/malik/cpit305/ap.html

More information

Distributed Systems Recitation 1. Tamim Jabban

Distributed Systems Recitation 1. Tamim Jabban 15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Tuesday: 9:30-11:59 AM Thursday: 10:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming

More information

Chapter 7 User-Defined Methods. Chapter Objectives

Chapter 7 User-Defined Methods. Chapter Objectives Chapter 7 User-Defined Methods Chapter Objectives Understand how methods are used in Java programming Learn about standard (predefined) methods and discover how to use them in a program Learn about user-defined

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

More information

CS/ENGRD 2110 SPRING Lecture 2: Objects and classes in Java

CS/ENGRD 2110 SPRING Lecture 2: Objects and classes in Java 1 CS/ENGRD 2110 SPRING 2014 Lecture 2: Objects and classes in Java http://courses.cs.cornell.edu/cs2110 Java OO (Object Orientation) 2 Python and Matlab have objects and classes. Strong-typing nature of

More information

COE318 Lecture Notes Week 4 (Sept 26, 2011)

COE318 Lecture Notes Week 4 (Sept 26, 2011) COE318 Software Systems Lecture Notes: Week 4 1 of 11 COE318 Lecture Notes Week 4 (Sept 26, 2011) Topics Announcements Data types (cont.) Pass by value Arrays The + operator Strings Stack and Heap details

More information

ECOM 2324 COMPUTER PROGRAMMING II

ECOM 2324 COMPUTER PROGRAMMING II ECOM 2324 COMPUTER PROGRAMMING II Object Oriented Programming with JAVA Instructor: Ruba A. Salamh Islamic University of Gaza 2 CHAPTER 9 OBJECTS AND CLASSES Motivations 3 After learning the preceding

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

PieNum Language Reference Manual

PieNum Language Reference Manual PieNum Language Reference Manual October 2017 Hadiah Venner (hkv2001) Hana Fusman (hbf2113) Ogochukwu Nwodoh( ocn2000) Index Introduction 1. Lexical Convention 1.1. Comments 1.2. Identifiers 1.3. Keywords

More information

Programming overview

Programming overview Programming overview Basic Java A Java program consists of: One or more classes A class contains one or more methods A method contains program statements Each class in a separate file MyClass defined in

More information

MIDTERM REVIEW. midterminformation.htm

MIDTERM REVIEW.   midterminformation.htm MIDTERM REVIEW http://pages.cpsc.ucalgary.ca/~tamj/233/exams/ midterminformation.htm 1 REMINDER Midterm Time: 7:00pm - 8:15pm on Friday, Mar 1, 2013 Location: ST 148 Cover everything up to the last lecture

More information

Lecture 3. Lecture

Lecture 3. Lecture True Object-Oriented programming: Dynamic Objects Static Object-Oriented Programming Reference Variables Eckel: 30-31, 41-46, 107-111, 114-115 Riley: 5.1, 5.2 D0010E Object-Oriented Programming and Design

More information

CS 1331 Exam 1 ANSWER KEY

CS 1331 Exam 1 ANSWER KEY CS 1331 Exam 1 Fall 2016 ANSWER KEY Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score. Signing signifies you are aware of and in

More information

COMP-202. Objects, Part III. COMP Objects Part III, 2013 Jörg Kienzle and others

COMP-202. Objects, Part III. COMP Objects Part III, 2013 Jörg Kienzle and others COMP-202 Objects, Part III Lecture Outline Static Member Variables Parameter Passing Scopes Encapsulation Overloaded Methods Foundations of Object-Orientation 2 Static Member Variables So far, member variables

More information

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Atelier Java - J1. Marwan Burelle.  EPITA Première Année Cycle Ingénieur. marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 3 4 Plan 1 2 3 4 A Bit of History JAVA was created in 1991 by James Gosling of SUN. The first public implementation (v1.0) in 1995.

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 26 March 26, 2015 Inheritance and Dynamic Dispatch Chapter 24 public interface Displaceable { public int getx(); public int gety(); public void move

More information

Types, Values and Variables (Chapter 4, JLS)

Types, Values and Variables (Chapter 4, JLS) Lecture Notes CS 141 Winter 2005 Craig A. Rich Types, Values and Variables (Chapter 4, JLS) Primitive Types Values Representation boolean {false, true} 1-bit (possibly padded to 1 byte) Numeric Types Integral

More information

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn how to describe objects and classes and how to define classes and create objects

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn how to describe objects and classes and how to define classes and create objects Islamic University of Gaza Faculty of Engineering Computer Engineering Dept Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn how to describe objects and classes and how to define

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors Agenda

More information

OO Programming Concepts

OO Programming Concepts Chapter 8 Objects and Classes 1 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections, loops, methods, and arrays. However, these Java

More information

Programming for Mobile Computing

Programming for Mobile Computing 1/57 Programming for Mobile Computing EECS 1022 moodle.yorku.ca Labs 2/57 For the things we have to learn before we can do them, we learn by doing them. Aristotle During the labs, carefully read the instructions,

More information

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles, Chapter 11 Inheritance and Polymorphism 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design

More information

Programming Language Concepts: Lecture 2

Programming Language Concepts: Lecture 2 Programming Language Concepts: Lecture 2 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 2, 19 January 2009 Classes and

More information

2. The object-oriented paradigm!

2. The object-oriented paradigm! 2. The object-oriented paradigm! Plan for this section:! n Look at things we have to be able to do with a programming language! n Look at Java and how it is done there" Note: I will make a lot of use of

More information

COE 212 Engineering Programming. Welcome to Exam I Tuesday November 11, 2014

COE 212 Engineering Programming. Welcome to Exam I Tuesday November 11, 2014 1 COE 212 Engineering Programming Welcome to Exam I Tuesday November 11, 2014 Instructors: Dr. Bachir Habib Dr. George Sakr Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam

More information