Object oriented aspects of Ada95

Size: px
Start display at page:

Download "Object oriented aspects of Ada95"

Transcription

1 Object oriented aspects of Ada Mikael Åsberg Amir Shariat Mälardalen University Department of Computer Science and Electronics June, 00

2 Abstract Have you ever wondered how a language would look like if you mixed a object oriented language such as Java with a imperative language for example C?. Put these in a mixer and whola, your new dish is called Ada. We can assure you, that the taste will vary through out the meal. Do not believe this is a boring repetition of your knowledge s of object oriented languages such as C++, Java or Smalltalk. Everything you think you know means something else in this fine programming language. When we did this paper and programmed with this language, we learned something new every day. This paper is not appropriate for programming ners, it is up to the reader to have knowledge of standard programming constructs. What we focus on, is the heart and soul of object oriented constructs. Such as inheritance, classes and objects. We do of course supply some explaining of the constructs of Ada in the ning of this paper, so that the reader does not get to confused considering the confusion he/she will experience when reading about the main topic of this paper. After the introduction, we walk the reader through the strange world of objects and classes in Ada. This chapter might get a bit confusing for readers who are used to the regular notion of classes in other programming languages. And last, we dedicate a whole chapter to inheritance in Ada. This chapter get s quite interesting due to Ada s strange implementation of objects and classes.

3 Contents Introduction to Ada. Specification and body files Functions and procedures Types Package Class and objects. Specification part (Encapsulation) Member variables Member functions Constructor Inheritance. Tagged and new Overriding Abstract types Polymorphism Generics Conclusion

4 Introduction to Ada. Specification and body files An Ada program consists of two parts, specification (.ads) and body (.adb). The specification part contains information that is visible, and the body part is the implementation (the specification part can have private declarations, see section.). This is similar to the C language where you have a.c file and a.h file. Something that is not similar, is that in Ada, the body does not need to include it s specification. Where in C, your.c file need to include its.h file, otherwise you can t see the information. That is not necessary in Ada, the body automatically sees its specification, so there is no need to include it. If you need to include some other package, then you need to use the keyword with. You will then get access to everything stated in the specification part of that package. Example: Figure : HelloWorld.adb with Ada. Text IO ; procedure HelloWorld i s Ada. Text IO. Put Line ( "Hello World!" ) ; end HelloWorld ; Here (Figure ), we can use any public information in Ada.Text IO by typing the package name, followed by any public information. In our case, the procedure Put Line. If you rather want direct access to the package, you can use the keyword use. Figure : HelloWorld.adb with Ada. Text IO ; use Ada. Text IO ; procedure HelloWorld i s Put Line ( "Hello World!" ) ; end HelloWorld ; In the example (Figure ), we can call Put Line without specifying which package. This is something that will make the code more readable. It should be used carefully. because it can lead to errors. Take a scenario where you include many packages that you are not so familiar with. The result might lead to that you end up calling the wrong procedure/function. Here is a small example on how specification and body files can look like. Figure : Example.ads package Example i s procedure Foo ; function Bar (A: I n t e g e r ) return I n t e g e r ; end Example ;

5 Figure : Example.adb with Ada. Text IO ; package body Example i s procedure Foo i s Ada. Text IO. Put Line ( "FooBar!" ) ; end Foo ; function Bar (A: I n t e g e r ) return I n t e g e r i s return A + ; end Bar ; end Example ; 0 We will explain packages, procedures, etc later. This is just to demonstrate how specification and body files work. We declared our procedure Foo and our function Bar in the specification part (Figure : & ), and implemented them in the body part (Figure ). In C, this is written as: // f i l e example. h void Foo ( ) ; int Bar ( int A) ; // f i l e example. c #i n c l u d e " example.h" #i n c l u d e "stdio.h" void Foo ( ) { p r i n t f ( "FooBar!" ) ; } int Bar ( int A) { return A+; } 0. Functions and procedures Arguments that are used in procedures and functions in Ada can have three modes, which basically defines the data flow. in - default mode, you can only read it. out - you can write to it and you can read from it, but you can t be sure that it s valid data (think null pointers). in out - you can both read from and write to it. Both functions and procedures are subprograms in Ada, and they have almost similar structure:

6 Figure : Function and procedure structure procedure Foo i s v a r i a b l e d e c l a r a t i o n s s t a t e m e n t s end Foo ; function Foo return <some data type > i s v a r i a b l e d e c l a r a t i o n s s t a t e m e n t s end Foo ; 0 The difference between them are: Procedures are not allowed to have a return statement, think of them like void functions in C. You can use all three modes for arguments in procedures. Functions must have a return statement. You can only use in mode for arguments in functions. Functions must be used in expressions. In other words, you can t ignore the return value. Some examples: Figure : Simple procedure procedure Bar (A: I n t e g e r ; B: out I n t e g e r ) i s B := A + ; end Foo ; You can t return a value in a procedure, but you can use the arguments to get values. Here (Figure ), argument B will have value A + after the procedure call. Figure : Simple swap procedure procedure Swap(A: in out I n t e g e r ; B: in out I n t e g e r ) i s Tmp: I n t e g e r ; l o c a l v a r i a b l e Tmp := A; A := B; B := Tmp; end Swap ; Another example (Figure ) where we use in out mode. Figure : Simple function to check if a number is even or not function EvenNumber (A: I n t e g e r ) return Boolean i s i f A mod = 0 then return True ; else return False ; end i f ; end EvenNumber ; Example of a function that will return a Boolean value (Figure ).

7 . Types Apart from the basic types like Integer, Char and Boolean etc., you can create your own types in Ada. type Day i s range.. ; type Month i s range.. ; Above, we have a type called Day with the values to, and a type Month with values to. As you can see, it is very easy to create your own types. It makes it easier to program, because you can easily create types that represent real-world data. Types are useful if you are writing a program that should be architecture independent. If you just declare a Integer variable and assign it a value, that is too high for that machine, then you will get an exception. With types you can do: type MyInteger i s range.. ; You can state the range of your variables. If an assignment is out of this range, Ada will give a runtime exception, which the programmer can catch. In this way, you can set the ranges of variables, so that they do not interfere with the machine dependent ranges of types. Ada has very strong type checking, so you can t assign a value from one type to a variable of different type. Figure : Example of two types procedure Main i s type Foo i s.. ; type Bar i s.. ; A : Foo ; B : Bar ; A := ; B := A; not a l l o w e d end Main ; Even if both our types represent the same type of values, in our example (Figure )... We can t assign the value of A to the variable B, because they are not of the same type. This kind of error will be found at compile time. You can catch them at a early stage, so it will lead to more secure code. There are times when you have two types that are very related, and it s unnecessary to create two kinds of types. A solution would be to create a type, and let the other type be a subtype. A simple example would be: Figure 0: Temperature example t y p e f o r temperatures, each s u b t y p e have range from a b s o l u t e zero s u r f a c e o f t h e sun type Temperature i s range ; subtype C e l s i u s i s Temperature range.. ; subtype Fahrenheit i s Temperature range 0.. 0;. Package Most programming languages has a way of structuring constructs, and hide information. For example classes in Java or C++. In Ada, packages are the primary way of capsulating constructs. We create packages when we need to structure related objects and subprograms. We saw a very simple example of this in section.. A package called Example where we had our specification in one file, and the implementation in another file.

8 Basically, a package consist of three parts: specification, body (which we discussed in.) and a private part. The private part is where you have information that you want to show the child packages. Let s go through a little more detailed example, so we understand the basics fully before we go into more complex stuff. Figure : SimpleCalc.ads package SimpleCalc i s type Fraction i s private ; function Create (A: I n t e g e r ; B: P o s i t i v e := ) return Fraction ; function Add(A, B: Fraction ) return Fraction ; private type Fraction i s NumVal : I n t e g e r ; DenVal : P o s i t i v e ; end ; end SimpleCalc ; 0 Here (Figure ), we have a package for a simple calculator for fractions. You can see on (Figure : ) that we have declared a private type called Fraction. This means that only the name ( Fraction ) is visible to the clients that uses this package, and not what the type contains. We specify the structure of Fraction in the private part (Figure : -), so it will be visible to child packages if we wish to extend it in the future. The type is a (s are like structs in C/C++) (Figure : 0-), with one numerator and one denominator. The denominator is declared as a Positive, because the denominator can not be zero or negative in a fraction. Positive is a predefined subtype in Ada: subtype P o s i t i v e i s I n t e g e r range.. I n t e g e r Last ; Since only the name, and not the structure of Fraction is visible (Figure : ). We cannot access the numerator and denominator in clients that uses this package (Figure : -). For example: Figure : Main.adb main f i l e w i l l not compile with SimpleCalc ; use SimpleCalc ; procedure Main i s F : Fraction ; F. NumVal := ; NumVal and DenVal are not v i s i b l e to us. F. DenVal := ; end Main ; Therefore, we need a function that creates a fraction (Figure : ). The function has two arguments, and one of them has a default value (B: Positive := ). To create a fraction, all we need to do is call the function Create (Figure : -).

9 Figure : Main.adb main f i l e w i l l be compiled c o r r e c t l y with SimpleCalc ; use SimpleCalc ; procedure Main i s F : Fraction ; F := Create (, ) ; F = / F := Create ( ) ; F = / end Main ; And here is the implementation for the specification file (Figure ). Figure : SimpleCalc.adb package body SimpleCalc i s function Create (A: I n t e g e r ; B: P o s i t i v e := ) return Fraction i s F : Fraction ; F. NumVal := A; F. DenVal := B; return F ; end Create ; function Add(A, B: Fraction ) return Fraction i s Result : F raction ; Result. NumVal := (A. NumVal B. DenVal ) + (A. DenVal B. NumVal ) ; Result. DenVal := A. DenVal B. DenVal ; return Result ; end Add ; end SimpleCalc ; 0 As you can see, this is a very simple example. We can extend this by for example adding a child package. You can see an example of this in section..

10 Class and objects. Specification part (Encapsulation) As mentioned before (see.), the specification file (.ads) exports the interface to other packages or procedures. It is important to only include what you want to show the outside world in this file, and hide the rest in the body file (.adb). There is however an exception, one can declare a private block in the specification which will not be visible to the outside world. This is shown below: Figure : export.ads package EXPORT i s This p a r t i s v i s i b l e to your c l i e n t s and t h e body. private This p a r t i s ONLY v i s i b l e to t h e body AND c h i l d packages, i. e. NOT your c l i e n t s. end EXPORT; 0 As shown above, your clients can only see the non-private part (Figure : -). The body and eventual child packages are able to see the whole specification. One can wonder, why does the private block (Figure : -) exist? Just put the part in the private block in the body and it will be equal? This question will be answered in the chapter which covers inheritance (see.). For now, we can say that it has something to do with the compiler and extending an object with the use of inheritance, or object specification. What should be included in the specification, that is, in the.ads file? Normally, function-, procedure- and object-specification is placed in the non-private block. The function and procedure implementation is placed in the body, the object implementation should be placed in the private block of the specification. If the object (type) should be considered to be able to be inherited, then the object implementation should always be placed in the private block of the specification. Again, we will cover all of this in the inheritance chapter (.).. Member variables When declaring member variables, one who is experienced with Java or C++, is used to have these declared in some private block in the body file or similar. In Ada, the private block is either the private block in the specification file, or just the body file. Member variables can of course be placed in either of them, the choice is up to the coder. An interesting aspect of Ada (at least Ada) is how you declare member variables. The example below shows the syntax. It looks kind of strange, compared with other object oriented languages.

11 Figure : show you how to declare member variables.ads package SHOW YOU HOW TO DECLARE MEMBER VARIABLES i s type OBJECT NAME; type OBJECT NAME i s L i s t your member v a r i a b l e s here member variable : I n t e g e r ; end ; end SHOW YOU HOW TO DECLARE MEMBER VARIABLES; 0 Figure : show you how to declare member variables.adb package body SHOW YOU HOW TO DECLARE MEMBER VARIABLES i s Put procedure and f u n c t i o n b o d i e s here i n s t a n c e : OBJECT NAME; end SHOW YOU HOW TO DECLARE MEMBER VARIABLES; We declare a new type called OBJECT NAME (Figure : ). Our new type is a, the contains one member called member variable (Figure : ). Note that there is no connection between the type (our object) and the package, which may be considered as the class. However, a package is not equal to the entity class, as we are used to in other modern object oriented languages. In fact, a package is allowed to contain any number of objects. Good object oriented programming may disagree with the fact of having several objects in one package. A detail worth noting, is that we tie the object to it s member variables in a unusual way. It s like declaring a struct in C, and call the struct name an object and refer to the struct s members as member variables. We see clearly how it looks like when object oriented principles are put on top of a, from the ning, imperative language. The code example above is approved by the compiler. Note that we don t use the private clause in the specification file. This is a serious threat to the encapsulation criteria, of object oriented thinking. Remember that your clients can see the whole specification file, except the private part. In this example, the client sees not only the object specification (Figure : ), but the object implementation too (Figure : -). This means that your client sees your private member variable member variable (Figure : ). In turn, this means that it can use your member variable. This is shown below. Note that our package body also sees the specification, so it can declare an instance of our new object (Figure : ). Figure : naughty client.adb with SHOW YOU HOW TO DECLARE MEMBER VARIABLES; use SHOW YOU HOW TO DECLARE MEMBER VARIABLES; procedure NAUGHTY CLIENT i s i n s t a n c e : OBJECT NAME; i n s t a n c e. member variable := The naughty c l i e n t uses t h e member v a r i a b l e d i r e c t l y! Do something e l s e end NAUGHTY CLIENT; 0

12 The above example is not good. The problem arises because we have our object implementation in the non-private part of the specification file. If we remove the implementation part of the visible part of the.ads file, then our problem is solved. As shown below. Figure : show you how to declare member variables.ads package SHOW YOU HOW TO DECLARE MEMBER VARIABLES i s type OBJECT NAME; end SHOW YOU HOW TO DECLARE MEMBER VARIABLES; Figure 0: show you how to declare member variables.adb package body SHOW YOU HOW TO DECLARE MEMBER VARIABLES i s Put procedure and f u n c t i o n b o d i e s here type OBJECT NAME i s L i s t your member v a r i a b l e s here member variable : I n t e g e r ; end ; i n s t a n c e : OBJECT NAME; end SHOW YOU HOW TO DECLARE MEMBER VARIABLES; 0 This solves our encapsulation problem, because we only show the the object specification (Figure : ) to the client. The client can t use our member variable directly, because it is no longer visible. However, the above example will not be accepted by the compiler. We will not dig any deeper into why this is the case. One can however say that the compiler want s the object specification (Figure : ), along with it s implementation (Figure 0 : -) in the same specification file. The private block in the specification file solves our problem. Our member variables will be hidden, and it will also be accepted by the compiler. The solution is shown below. Figure : show you how to declare member variables.ads package SHOW YOU HOW TO DECLARE MEMBER VARIABLES i s type OBJECT NAME i s private ; private type OBJECT NAME i s L i s t your member v a r i a b l e s here member variable : I n t e g e r ; end ; end SHOW YOU HOW TO DECLARE MEMBER VARIABLES; 0 0

13 Figure : show you how to declare member variables.adb package body SHOW YOU HOW TO DECLARE MEMBER VARIABLES i s Put procedure and f u n c t i o n b o d i e s here i n s t a n c e : OBJECT NAME; end SHOW YOU HOW TO DECLARE MEMBER VARIABLES; Note that we have declared our object (Figure : ) as private. This means that the compiler expects the object body in the private block (Figure : -). If you don t declare the object as private in the declaration, but still have it s body in the private block, then you will get an error from the compiler. The same goes if you declare an object as private, and don t have it s implementation in the private block. The compiler wont complain about the above example, and the client cannot use your member variable (Figure : 0) directly.. Member functions In the object oriented thinking, an object is associated with not only a state. I.e. it s member variables for which we covered in the previous chapter. An object is also associated with it s member functions. That is, the operations that a client is permitted to do on an object. Ada has their own name for member functions (not surprising), called primitive functions. Note that in Ada, both functions and procedures are allowed to be primitive functions of an object. Just because a function or procedure is placed in the same package as an object. This does not imply that it automatically becomes a primitive function (member function) to an object in that package. Remember that we stated earlier (see.) in this paper, that a package can hold a arbitrary number of objects. How do we know which functions or procedures belong to which object? When we deal with member variables it s easy. The variables are tied to it s object through the and type. To solve this conflict, a function or procedure must follow some criteria for it to be considered as a primitive function. This criteria [ARI0] is stated below. A function or procedure is a primitive function to an object if it has the object s type as part of it s parameter list or if it is the returning type of the function. The above stated rule sorts out which functions or procedures belong to which object. That s pretty much what could be said about member functions. Let s finish this chapter with a code example.

14 Figure : show you how to declare member functions.ads package SHOW YOU HOW TO DECLARE MEMBER FUNCTIONS i s type OBJECT NAME i s private ; L i s t your f u n c t i o n s or procedures, p r i m i t i v e or not function GET MEMBER VARIABLE( obj : OBJECT NAME) return I n t e g e r ; procedure SET MEMBER VARIABLE( obj : out OBJECT NAME; new value : in I n t e g e r ) ; procedure NOT A PRIMITIVE FUNCTION( temp : S t r i n g ) ; private type OBJECT NAME i s L i s t your member v a r i a b l e s here member variable : I n t e g e r ; end ; end SHOW YOU HOW TO DECLARE MEMBER FUNCTIONS; 0 Figure : show you how to declare member functions.adb package body SHOW YOU HOW TO DECLARE MEMBER FUNCTIONS i s Put procedure and f u n c t i o n b o d i e s here function GET MEMBER VARIABLE( obj : OBJECT NAME) return I n t e g e r i s return obj. member variable ; end GET MEMBER VARIABLE; procedure SET MEMBER VARIABLE( o b j : out OBJECT NAME; new value : in I n t e g e r ) i s o b j. member variable := new value ; end SET MEMBER VARIABLE; procedure NOT A PRIMITIVE FUNCTION( temp : S t r i n g ) i s null ; end NOT A PRIMITIVE FUNCTION ; end SHOW YOU HOW TO DECLARE MEMBER FUNCTIONS; 0 0 In the code example, we see that a function and a procedure (Figure : -) are the only two member functions of object OBJECT NAME. Note that if the function GET MEMBER VARIABLE (Figure : ) had the type OB- JECT NAME as the returning type, instead of having the OBJECT NAME as an argument. The function would still be considered as a primitive function of OBJECT NAME.. Constructor There is no correspondence to the C++ term constructor in Ada. That is, a special function with the same name as the class. Which can be used to set an object s values when it is created. However, there is a way to set an object s values when creating it in Ada. This facility is a functionality that has to do with the type. We will not do any explaining of types in this

15 paper. The type is however a part of the object oriented aspect of Ada. We will show a small example of how to set values to an object, when instanced. Figure : show you how to imitate a constructor.ads package SHOW YOU HOW TO IMITATE A CONSTRUCTOR i s type OBJECT NAME( member value : I n t e g e r ) i s private ; private type OBJECT NAME( member value : I n t e g e r ) i s L i s t your member v a r i a b l e s here member variable : I n t e g e r := member value ; end ; end SHOW YOU HOW TO IMITATE A CONSTRUCTOR; 0 Figure : client uses the fake constructor functionality.adb package body CLIENT USES THE FAKE CONSTRUCTOR FUNCTIONALITY i s i n s t a n c e : OBJECT NAME( ) ; end CLIENT USES THE FAKE CONSTRUCTOR FUNCTIONALITY; Note that we have constructed a way to have arguments (Figure : & ) to a. This argument list is a construct of the type. The arguments are read-only values. However, as we said earlier, we will not present types in this paper. If the reader has further interest in this matter, please have a look in an Ada tutorial.

16 Inheritance. Tagged and new First of all we need to clarify this. When we say type, we also refer to the term object. In Ada, if you want a type to be inheritable, you must declare it as tagged. You can t inherit from a type if it is not declared tagged. The syntax is shown in the example below. By the way, when we say type in this context. We also refer to the term class in other object oriented languages. The class definition that we are used to, does not really exist in Ada. There is no specification of objects, other than when we declare a type consisting of a, and the type s primitive functions. If you want to inherit from a type, you declare a new type with the reserved word new. Your new type will have the parent member variables, and the member functions and procedures known as primitive functions. Let s have a look at the syntax for declaring a type as inheritable. Figure : show you how to declare a object inheritable.ads package SHOW YOU HOW TO DECLARE A OBJECT INHERITABLE i s type PARENT OBJECT i s tagged private ; L i s t your f u n c t i o n s or procedures, p r i m i t i v e or not function GET MEMBER VARIABLE( obj : PARENT OBJECT) return I n t e g e r ; procedure SET MEMBER VARIABLE( o b j : out PARENT OBJECT; new value : in I n t e g e r ) ; procedure NOT A PRIMITIVE FUNCTION( temp : S t r i n g ) ; Not i n h e r i t a b l e private type PARENT OBJECT i s tagged L i s t your member v a r i a b l e s here member variable : I n t e g e r ; I n h e r i t a b l e end ; end SHOW YOU HOW TO DECLARE A OBJECT INHERITABLE; 0 0 The new syntax is shown on the lines (Figure : & ). The type PARENT OBJECT has the new property tagged. A quite interesting aspect, is that a child only inherits the primitive functions (Figure : -). And of course the member variable member variable (Figure : ). If a child calls the function NOT A PRIMITIVE FUNCTION, an error will occur if the function is not implemented in the child. How does one do to inherit from a type? The keyword new must be used to state that this new type is indeed an extension of a existing type. In other words, the new is comparable with, for example, Java s extends. It s simply a statement saying that this object A, inherits from object B. Let s have a look at how the child does to inherit from our object (type) PARENT OBJECT.

17 Figure : show you how to inherit from a object.ads package SHOW YOU HOW TO INHERIT FROM A OBJECT i s type CHILD OBJECT i s new PARENT OBJECT with private ; L i s t your f u n c t i o n s or procedures, p r i m i t i v e or not function CHILDS GET MEMBER VARIABLE( o b j : CHILD OBJECT) return I n t e g e r ; procedure CHILDS SET MEMBER VARIABLE( o b j : out CHILD OBJECT; new value : in I n t e g e r ) ; procedure NOT A PRIMITIVE FUNCTION( temp : S t r i n g ) ; private type CHILD OBJECT i s new PARENT OBJECT with L i s t your member v a r i a b l e s here c h i l d m e m b e r v a r i a b l e : I n t e g e r ; Child s new member v a r i a b l e The parent v a r i a b l e member variable i s p a r t o f CHILD OBJECT end ; end SHOW YOU HOW TO INHERIT FROM A OBJECT; 0 0 The functions (Figure : -0) are not overridden (will be covered in.), they are the child s own functions. Otherwise, nothing new to say regarding the functions (Figure : -0). Notice how we put the keyword new (Figure : & ). We say that the type CHILD OBJECT extends the type PARENT OBJECT. Also notice the new keyword with, that comes right after the parent object name. When declaring new, we must also include the with. The part after with can be interpreted as the extended part, besides the parent part. If you do not wish to extend the child with anything, then the following syntax can be used. Figure : show you how to inherit from a object but not extend.ads package SHOW YOU HOW TO INHERIT FROM A OBJECT BUT NOT EXTEND i s type CHILD OBJECT i s new PARENT OBJECT with private ; L i s t your f u n c t i o n s or procedures, p r i m i t i v e or not function CHILDS GET MEMBER VARIABLE( o b j : CHILD OBJECT) return I n t e g e r ; procedure CHILDS SET MEMBER VARIABLE( o b j : out CHILD OBJECT; new value : in I n t e g e r ) ; procedure NOT A PRIMITIVE FUNCTION( temp : S t r i n g ) ; private type CHILD OBJECT i s new PARENT OBJECT with null ; end SHOW YOU HOW TO INHERIT FROM A OBJECT BUT NOT EXTEND; 0 Note the content on line (Figure : ): null. We could interpret this as: extend the object PARENT OBJECT with a empty. We must mention because the parent type has a, and must be referred to. It is our choice however, to put extra data in this referenced or not. Ada s syntax is somewhat fuzzy, and therefore it is sometimes difficult to exactly explain the syntax. The above examples do not say anything about how the package with the child type includes the package with the parent type. There are actually two ways to do this. Either just use

18 the keyword with in the package with the child object. Or let it be a child package to the package containing the parent object. Depending on the choice, the package containing the parent object will look different. The first mentioned solution is not good, considering the object oriented property encapsulation. The second solution holds this property. Let s start with the non-encapsulated solution. Figure 0: non encapsualted parent.ads package NON ENCAPSULATED PARENT i s type PARENT OBJECT i s tagged private ; L i s t your f u n c t i o n s or procedures, p r i m i t i v e or not type PARENT OBJECT i s tagged L i s t your member v a r i a b l e s here member variable : I n t e g e r ; I n h e r i t a b l e end ; end NON ENCAPSULATED PARENT; 0 Figure : child that includes parent.ads with NON ENCAPSULATED PARENT; package CHILD THAT INCLUDES PARENT i s A l l t h e c h i l d s t u f f end CHILD THAT INCLUDES PARENT; Focus on the package with the parent type PARENT OBJECT (Figure 0 : -). Notice that we have removed the private block. Remember that a package with a ordinary with, can only see the non-private part of the.ads file that it includes. If we had not removed it, then the package containing the child object would not have access to the parent object body. This implies that inheritance is impossible, according to the compiler. The compiler cannot decide for example, if the child object has declared a new member variable with the same name as one in the parent object. This is illegal of course. This is the case because, in the scope of the package with the child object. The parent member variables are not visible. The compiler cannot determine wether there is an error or not. This is of course dangerous and not acceptable. That is why an error occurs in this case. This solution works of course, the compiler wont mind. The philosophy of object orientation will however not agree. The parents member variables are visible to the child, that is not good. This slight problem can be solved by using child packages.

19 Figure : encapsulated parent.ads package ENCAPSULATED PARENT i s type PARENT OBJECT i s tagged private ; L i s t your f u n c t i o n s or procedures, p r i m i t i v e or not private type PARENT OBJECT i s tagged L i s t your member v a r i a b l e s here member variable : I n t e g e r ; I n h e r i t a b l e end ; end ENCAPSULATED PARENT; 0 Figure : encapsulated parent-child.ads package ENCAPSULATED PARENT. CHILD i s A l l t h e c h i l d s t u f f end ENCAPSULATED PARENT. CHILD ; The parent has again a private block, which is nice considering information hiding. Notice that the package containing the child object, is now a child package to the package containing the parent object. The child package can see the private part of the parent, so the compiler is happy. Finally, let s look shortly at how we can use the child. Figure : parent.ads package PARENT i s type PARENT OBJECT( value : I n t e g e r ) i s tagged private ; L i s t your f u n c t i o n s or procedures, p r i m i t i v e or not private type PARENT OBJECT( value : I n t e g e r ) i s tagged L i s t your member v a r i a b l e s here member variable : I n t e g e r := value ; I n h e r i t a b l e end ; end PARENT; 0

20 Figure : parent-child.ads package PARENT. CHILD i s type CHILD OBJECT i s new PARENT OBJECT with private ; L i s t your f u n c t i o n s or procedures, p r i m i t i v e or not private type CHILD OBJECT i s new PARENT OBJECT with L i s t your member v a r i a b l e s here c h i l d m e m b e r v a r i a b l e : I n t e g e r ; Child s new member v a r i a b l e The parent v a r i a b l e member variable i s p a r t o f CHILD OBJECT end ; end PARENT. CHILD ; 0 Figure : main.adb with PARENT. CHILD ; use PARENT. CHILD ; procedure main i s c h i l d : CHILD OBJECT ( ) ; The parent v a r i a b l e get s t h e v a l u e null ; end main ; The child can override parent functions and procedures, this will be covered later (.). The child cannot manipulate the inherited member variables from the parent. Except by using the argument list (Figure : ) in the procedure main. The child is not permitted to have a argument list, if the parent has one. In the above example, the parent member variable will have the value inserted. If the parent did not have a argument list, then the child would be permitted to have one. And by this way, initiate it s member variables through this list. To set it s member values in the above example, a procedure is needed to do this.. Overriding Overriding functions or procedures in Ada, looks somewhat strange. At first glance, it looks like overloading, if compared to other object oriented languages. Overloading is when you have the same function name. You have however different parameter types or amount, or different return types. Overridden functions are identical to each other, and they are connected to inheritance. For which overloading is not. As stated before, overriding in Ada could easily be mistaken for overloading. Let s look at a example of overriding.

21 Figure : parent.ads package PARENT i s type PARENT OBJECT i s tagged private ; function PARENTS GET MEMBER VARIABLE( obj : PARENT OBJECT) return I n t e g e r ; procedure PARENTS SET MEMBER VARIABLE( o b j : out PARENT OBJECT; new value : in I n t e g e r ) ; private type PARENT OBJECT i s tagged member variable : I n t e g e r ; I n h e r i t a b l e end ; end PARENT; 0 Figure : parent-child.ads package PARENT. CHILD i s type CHILD OBJECT i s new PARENT OBJECT with private ; function PARENTS GET MEMBER VARIABLE( obj : CHILD OBJECT) return I n t e g e r ; procedure PARENTS SET MEMBER VARIABLE( o b j : out CHILD OBJECT; new value : in I n t e g e r ) ; procedure PARENTS SET MEMBER VARIABLE( o b j : out PARENT OBJECT; new value : in I n t e g e r ) ; private type CHILD OBJECT i s new PARENT OBJECT with c h i l d m e m b e r v a r i a b l e : I n t e g e r ; Child s new member v a r i a b l e end ; end PARENT. CHILD ; 0 The parent has two functions (Figure : -) which are primitive to PARENT OBJECT, otherwise nothing new. Let s look at the child. The function and procedure on (Figure : -) are primitive to CHILD OBJECT. It looks like these two functions are overloaded, since the types in the parameters differ from the one s in the parent. These two functions (Figure : -) are overridden. The cause of this confusion, comes from the fact that Ada put s the calling object as a parameter, instead of the dot-notation. Compare these two constructs:

22 parent : PARENT OBJECT; c h i l d : CHILD OBJECT; PARENTS GET MEMBER VARIABLE( parent ) ; PARENTS GET MEMBER VARIABLE( c h i l d ) ; PARENT OBJECT parent = new PARENT OBJECT( ) ; CHILD OBJECT c h i l d = new CHILD OBJECT ( ) ; parent.parents GET MEMBER VARIABLE( ) ; c h i l d.parents GET MEMBER VARIABLE( ) ; It is all about where you put the calling object. If the child calls one of the two functions (Figure : -) and they are implemented in the child body: It is then the child functions that are called. If the child does not declare a parent function, with it s child object as parameter. A function call by the child, will call the parent function. What about the procedure on line (Figure : ) in the child specification? It looks like a overridden function, but it is not. In fact, the child can implement this function. The compiler does not give any error. Until you try to make a call to this function, with the parent as object caller. You will then get an error. The compiler does not know which of the two to call, since the object matches both function parameters. If you call the function with the child object as an argument, you will not get any complaints from the compiler. And if you run the program, the parent function is called, and not the child. The child implementation will never be used, so the procedure on line (Figure : ) is never called. The compiler knows which function to call, the parent, that is why it does not complain. The child function does not match when considering the parameter. The parent function matches exactly, because it is inherited. When you inherit, you can call the parent functions with your child object as the argument.. Abstract types Declaring a type as abstract in Ada, is comparable with declaring a abstract class in other programming languages. The perhaps biggest difference, is that in Ada, you are not allowed to create an instance of a abstract type in any way. A specification (.ads) declaring a abstract type with it s belonging abstract functions or procedures, do not need to have a body file (.adb). In fact, it is not even allowed to have body file. It is enough that at least one construct in the specification is non-abstract, for the compiler to complain. If this is the case, then a body must exist with the implementation. If a package inherits from a abstract type, then the parent s primitive abstract functions must be overridden. This means that the child must supply these parent functions with a body. Note that in general, all construct specifications must have a body (implementation). Let s have a look at an example of a abstract type. 0 0

23 Figure : abstract parent.ads package ABSTRACT PARENT i s type PARENT OBJECT i s abstract tagged private ; function PARENTS GET MEMBER VARIABLE( obj : PARENT OBJECT) return I n t e g e r i s abstract ; procedure PARENTS SET MEMBER VARIABLE( o b j : out PARENT OBJECT; new value : in I n t e g e r ) i s abstract ; private type PARENT OBJECT i s abstract tagged member variable : I n t e g e r ; end ; end ABSTRACT PARENT; 0 If you want to use the keyword abstract (Figure : ), then it must be written directly after is. Another notation is that if you mark a type as abstract, then it must also be marked as tagged. One could say that the phrase (Figure : ) abstract tagged is one keyword, when considering types as abstract. Let s consider the lines (Figure : -). Note that these functions and procedures are marked as abstract. Primitive functions and abstract functions do not really have anything in common. If a function is abstract but not primitive, then it does not need a body thanks to abstract. It is not primitive, so a child does not inherit it, and thus do not need to override it. Similar if we have a primitive function, that is not abstract. The package that contains the abstract type, must also have a body file (.adb) with the function body. However, this function must not be overridden by the child. It is possible to override it however, since it is primitive. One last thing about abstract functions and procedures. If the type is not abstract, then it s primitive functions and procedures are not allowed to be abstract either. We will not show any code example of a child inheriting from a abstract parent type, since it look s the same as in previous examples in this chapter. A remark is that the child must override the parent functions and procedures, that are both primitive and abstract. Besides this, there is nothing more to add about types that inherit from abstract tagged types.. Polymorphism Polymorphism is the concept of something having different forms. This small chapter will deal with heterogenous in the essence of datastructure s. Ada is a safe language, this means that it is extremely strong typed. Which in turn means that it almost lacks heterogeneous properties. This is why this chapter is small, and difficult to write about. We stated in the last chapter, that it is forbidden to declare a type that is abstract. In other object oriented languages, the term abstract is important for creating polymorphic variables. In Ada, this is not the case. Abstract in Ada does not contribute to polymorphism, but inheritance is however very important for this concept. As mentioned earlier, Ada is very strong typed. There is however a construct in Ada that gives some polymorphic property. Class wide types is the name of that construct, it looks like this. procedure HAS CLASS WIDE TYPE AS PARAMETER( obj : in PARENT OBJECT Class ) ; We will not go into detail about the special apostrophe functions, such as the above. What is important to know, is that when you declare a type followed by an apostrophe, and then the

24 keyword Class. All derived types of that type are then allowed values, including the type itself. Note that you are not allowed to declare a class wide type such as: obj : PARENT OBJECT Class ; I l l e g a l Class wide types are allowed as parameter to functions and procedures. Types that are of access type, are allowed to point to class wide types. similar to pointers in C, here is an example: Access types are type POINTER TO PARENT OBJECT TYPES i s access PARENT OBJECT C l a s s ; The above means that we declare an new type called POINTER TO PARENT-OBJECT TYPES. This is a access type which is allowed to point to objects that are of type PARENT OBJECT, and all of it s derived types. Access types are allowed to point to any type, not just to class wide types. We will not go any further with access types. This paper is about the object oriented aspects such as polymorphism, and not types. Here is an example of how polymorphism can be achieved in Ada. Figure 0: example of polymorphism.ads package EXAMPLE OF POLYMORPHISM i s with Ada. Text IO ; use Ada. Text IO ; type PARENT OBJECT( param : I n t e g e r ) i s tagged private ; type POINTER TO PARENT CLASS i s access PARENT OBJECT Class ; procedure argument is PARENT CLASS ( obj : in PARENT OBJECT Class ) ; procedure DISPATCHING PROCEDURE( o b j : PARENT OBJECT) ; procedure argument is POINTER TO PARENT CLASS ( obj : in POINTER TO PARENT CLASS ) ; type CHILD OBJECT i s new PARENT OBJECT with private ; procedure DISPATCHING PROCEDURE( o b j : CHILD OBJECT ) ; private type PARENT OBJECT( param : I n t e g e r ) i s tagged p a r e n t v a r i a b l e : I n t e g e r := param ; end ; type CHILD OBJECT i s new PARENT OBJECT with c h i l d v a r i a b l e : I n t e g e r ; end ; end EXAMPLE OF POLYMORPHISM; 0 0 0

25 Figure : example of polymorphism.adb package body EXAMPLE OF POLYMORPHISM i s procedure argument is PARENT CLASS ( obj : in PARENT OBJECT Class ) i s DISPATCHING PROCEDURE( obj ) ; end argument is PARENT CLASS ; procedure DISPATCHING PROCEDURE( o b j : PARENT OBJECT) i s Put Line ( "PARENT: " & I n t e g e r Image ( obj. p a r e n t v a r i a b l e ) ) ; end DISPATCHING PROCEDURE; procedure argument is POINTER TO PARENT CLASS ( obj : in POINTER TO PARENT CLASS) i s Put Line ( " POINTER : " & I n t e g e r Image ( obj. p a r e n t v a r i a b l e ) ) ; end argument is POINTER TO PARENT CLASS ; procedure DISPATCHING PROCEDURE( o b j : CHILD OBJECT) i s Put Line ( "CHILD: " & I n t e g e r Image ( obj. p a r e n t v a r i a b l e ) ) ; end DISPATCHING PROCEDURE; end EXAMPLE OF POLYMORPHISM; 0 0 Figure : Main.adb with EXAMPLE OF POLYMORPHISM; use EXAMPLE OF POLYMORPHISM; procedure Main i s HeterogenArray : array (.. ) of POINTER TO PARENT CLASS; ParentInstance : PARENT OBJECT( ) ; C h i l d I n s t a n c e : CHILD OBJECT ( ) ; HeterogenArray ( ) := new PARENT OBJECT( 0 ) ; HeterogenArray ( ) := new CHILD OBJECT( 0 ) ; for temp in.. loop argument is POINTER TO PARENT CLASS ( HeterogenArray ( temp ) ) ; end loop ; argument is PARENT CLASS ( ParentInstance ) ; argument is PARENT CLASS ( C h i l d I n s t a n c e ) ; end Main ; 0 Before we give an explanation of the above code, let s with looking at the output that this program generates. POINTER: 0 POINTER: 0 PARENT: CHILD : Our package EXAMPLE OF POLYMORPHISM (Figure 0 ), contains two types with one primitive procedure each. The file also contains a type

26 POINTER TO PARENT CLASS, which is a access variable. It too has it s own primitive procedure. About the package body (Figure ). The function call Integer Image (Figure : 0 & & ), converts an Integer and returns a corresponding String. The Main file (Figure ) contains two important things. First we have a heterogenous array (Figure : ), which contains pointer types. These may point to all PARENT OBJECT, and it s children. We call a procedure (Figure : ), which prints the argument object s member variable parent variable. Note that the procedure (Figure : ) may take this pointer type as an argument, but you may not put a PARENT OBJECT or CHILD OBJECT into this procedure. Even though this pointer type can only point to one of these two types! Ada just matches the types, and the type POINTER TO PARENT CLASS is not the types PARENT OBJECT or CHILD OBJECT. Second, at the lines (Figure : -), we insert the parent and child object. This is ok since the procedure argument is PARENT CLASS takes the class wide type PARENT OBJECT Class as argument. Note that this procedure makes a dispatching call to DISPATCHING PROCEDURE (Figure : ). Depending on the type of object, either the parent or the child procedure DIS- PATCHING PROCEDURE is called.. Generics In C++, a programmer can use templates to create classes or functions that operates on generic types. The result will be less code. You can also do this in Ada, this it is called generics. For example, if we take a look at the swap procedure (Figure ) that we created in section. on page. Figure : Swap procedure procedure Swap(A: in out I n t e g e r ; B: in out I n t e g e r ) i s Tmp: I n t e g e r ; Tmp := A; A := B; B := Tmp; end Swap ; Let s say we want another procedure for swapping Float data types. Instead of rewriting the entire procedure, and replacing every Integer with Float. We can create a generic procedure that handles any generic data type. We by creating a private type, and declaring our procedure in the specification file (Figure ). Figure : Generic specification generic type G Type i s private ; procedure GenSwap(A: in out G Type ; B: in out G Type ) ; The new swap procedure is pretty much the same as the previous one. We replaced Integer with G Type, that is our generic type (Figure ).

27 Figure : Generic implementation procedure GenSwap(A: in out G Type ; B: in out G Type ) i s Tmp: G Type ; Tmp := A; A := B; B := Tmp; end GenSwap ; And from that generic procedure (Figure ), we can create instances of swap functions for other data types (Figure ). Figure : Create instances procedure FSwap i s new GenSwap( Float ) ; procedure ISwap i s new GenSwap( I n t e g e r ) ; The same can be done with packages. Lets say, for example, you have a basic queue package. Instead of limiting the queue to Integers, Floats or any other data type. You can create a generic package that will handle any kind of data type (Figure and Figure ). Figure : GenQueue.ads generic type Item i s private ; S i z e : P o s i t i v e := 0 0 ; d e f a u l t v a l u e package GenQueue i s procedure Add( I : Item ) ; function Count return Natural ; OverFlow : exception ; end GenQueue ; Figure : GenQueue.adb package body GenQueue i s type Data i s array ( P o s i t i v e range <>) of Item ; Q : Data (.. S i z e ) ; P : Natural := 0 ; procedure Add( I : Item ) i s i f P >= S i z e then raise OverFlow ; end i f ; P := P + ; Q(P) := I ; end ; function Count return Natural i s return P; end Count ; end GenQueue ; 0 0 And as before, we need to create an instance of the generic package before we can use it. For example, if you need to store Boolean values in the queue. All you have to do is to create an instance (Figure ).

28 Figure : Instances of generic packages package BoolQueue i s new GenQueue ( S i z e => 0, Item => Boolean ) ; we don t need t h e f i r s t parameter s i n c e we gave S i z e a d e f a u l t v a l u e package BoolQueue i s new GenQueue ( Item => Boolean ) ;

29 Conclusion Ada is the parent of Ada. The first mentioned version of Ada was a imperative language, and the second version was developed to have object orientation. It looks like object orientation has been glued together with the former imperative properties. Note that the developers did not change the languages structure. They just added some extra stuff on top of the original programming language structure. This causes some confusion, the language get s overwhelmed with complication. In turn, it get s very difficult to learn the language. Ada00 is a further development, which at least includes the dot notation when a object s function or procedure is called. Other new properties of Ada00 [RFA] is interface (like in Java), and multiple inheritance just to mention a few. Ada is suppose to be a safe language, and no doubt, it has such facilities. For example the amazingly strong typing. The unnecessary complication that has been introduced due to the object oriented aspects, kind of ruins the idea of safety. From the programmers point of view, we believe that logical errors may occur due to the fact that Ada does not follow the standard programming construct of object orientation. What should have been done, was to build the language from scratch, and throw away all the imperative constructs. Ada00 is not build from scratch, so it too has imperative construct belongings from Ada. Though it has many object oriented improvements, it is still not near the looks of other OO languages. Our last words are these. If we were to choose a OO languages to work in, and our application was not of safety-critical nature, then our choice would not be any current version of Ada.

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

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Lecturer: William W.Y. Hsu. Programming Languages

Lecturer: William W.Y. Hsu. Programming Languages Lecturer: William W.Y. Hsu Programming Languages Chapter 9 Data Abstraction and Object Orientation 3 Object-Oriented Programming Control or PROCESS abstraction is a very old idea (subroutines!), though

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

More information

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc. Chapter 13 Object Oriented Programming Contents 13.1 Prelude: Abstract Data Types 13.2 The Object Model 13.4 Java 13.1 Prelude: Abstract Data Types Imperative programming paradigm Algorithms + Data Structures

More information

CPS 506 Comparative Programming Languages. Programming Language

CPS 506 Comparative Programming Languages. Programming Language CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support

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 10 :: Data Abstraction and Object Orientation

Chapter 10 :: Data Abstraction and Object Orientation Chapter 10 :: Data Abstraction and Object Orientation Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier Chapter10_Data_Abstraction_and_Object_Orientation_4e 1 Object-Oriented

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

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

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

Type Checking and Type Equality

Type Checking and Type Equality Type Checking and Type Equality Type systems are the biggest point of variation across programming languages. Even languages that look similar are often greatly different when it comes to their type systems.

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

Super-Classes and sub-classes

Super-Classes and sub-classes Super-Classes and sub-classes Subclasses. Overriding Methods Subclass Constructors Inheritance Hierarchies Polymorphism Casting 1 Subclasses: Often you want to write a class that is a special case of an

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information

Data Abstraction. Hwansoo Han

Data Abstraction. Hwansoo Han Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

CSE 12 Abstract Syntax Trees

CSE 12 Abstract Syntax Trees CSE 12 Abstract Syntax Trees Compilers and Interpreters Parse Trees and Abstract Syntax Trees (AST's) Creating and Evaluating AST's The Table ADT and Symbol Tables 16 Using Algorithms and Data Structures

More information

Chapter 9 :: Data Abstraction and Object Orientation

Chapter 9 :: Data Abstraction and Object Orientation Chapter 9 :: Data Abstraction and Object Orientation Programming Language Pragmatics Michael L. Scott Control or PROCESS abstraction is a very old idea (subroutines!), though few languages provide it in

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Design issues for objectoriented. languages. Objects-only pure language vs mixed. Are subclasses subtypes of the superclass? Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables

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

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

6.001 Notes: Section 15.1

6.001 Notes: Section 15.1 6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define

More information

Lecture 2, September 4

Lecture 2, September 4 Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due

More information

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs. Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar

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

377 Student Guide to C++

377 Student Guide to C++ 377 Student Guide to C++ c Mark Corner January 21, 2004 1 Introduction In this course you will be using the C++ language to complete several programming assignments. Up to this point we have only provided

More information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered

More information

Overriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון

Overriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון Overriding עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap A method in a child class overrides a method in the parent class if it has the same name and type signature: Parent void method(int,float)

More information

How to approach a computational problem

How to approach a computational problem How to approach a computational problem A lot of people find computer programming difficult, especially when they first get started with it. Sometimes the problems are problems specifically related to

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

C++ for Java Programmers

C++ for Java Programmers Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

More information

Module 10 Inheritance, Virtual Functions, and Polymorphism

Module 10 Inheritance, Virtual Functions, and Polymorphism Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL 10.1: Inheritance Fundamentals... 2 CRITICAL SKILL 10.2: Base Class Access Control... 7 CRITICAL SKILL 10.3:

More information

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Lecture 04 Software Test Automation: JUnit as an example

More information

COMP322 - Introduction to C++

COMP322 - Introduction to C++ COMP322 - Introduction to C++ Winter 2011 Lecture 08 - Inheritance continued School of Computer Science McGill University March 8, 2011 Last Time Single Inheritance Polymorphism: Static Binding vs Dynamic

More information

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

the gamedesigninitiative at cornell university Lecture 7 C++ Overview Lecture 7 Lecture 7 So You Think You Know C++ Most of you are experienced Java programmers Both in 2110 and several upper-level courses If you saw C++, was likely in a systems course Java was based on

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file? QUIZ on Ch.5 Why is it sometimes not a good idea to place the private part of the interface in a header file? Example projects where we don t want the implementation visible to the client programmer: The

More information

09/02/2013 TYPE CHECKING AND CASTING. Lecture 5 CS2110 Spring 2013

09/02/2013 TYPE CHECKING AND CASTING. Lecture 5 CS2110 Spring 2013 1 TYPE CHECKING AND CASTING Lecture 5 CS2110 Spring 2013 1 Type Checking 2 Java compiler checks to see if your code is legal Today: Explore how this works What is Java doing? Why What will Java do if it

More information

CPS122 Lecture: From Python to Java

CPS122 Lecture: From Python to Java Objectives: CPS122 Lecture: From Python to Java last revised January 7, 2013 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Object Model Comparisons

Object Model Comparisons Object Model Comparisons 1 Languages are designed, just like programs Someone decides what the language is for Someone decides what features it's going to have Can't really understand a language until

More information

Programming Languages 2nd edition Tucker and Noonan"

Programming Languages 2nd edition Tucker and Noonan Programming Languages 2nd edition Tucker and Noonan" Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance..."

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

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)

More information

Designing Robust Classes

Designing Robust Classes Designing Robust Classes Learning Goals You must be able to:! specify a robust data abstraction! implement a robust class! design robust software! use Java exceptions Specifications and Implementations

More information

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed?

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed? QUIZ Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed? Or Foo(x), depending on how we want the initialization

More information

Construction: High quality code for programming in the large

Construction: High quality code for programming in the large Construction: High quality code for programming in the large Paul Jackson School of Informatics University of Edinburgh What is high quality code? High quality code does what it is supposed to do......

More information

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every

More information

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are built on top of that. CMSC131 Inheritance Object When we talked about Object, I mentioned that all Java classes are "built" on top of that. This came up when talking about the Java standard equals operator: boolean equals(object

More information

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26 COSC 2P95 Procedural Abstraction Week 3 Brock University Brock University (Week 3) Procedural Abstraction 1 / 26 Procedural Abstraction We ve already discussed how to arrange complex sets of actions (e.g.

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

CPS122 Lecture: From Python to Java last revised January 4, Objectives: Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style CS125 : Introduction to Computer Science Lecture Notes #4 Type Checking, Input/Output, and Programming Style c 2005, 2004, 2002, 2001, 2000 Jason Zych 1 Lecture 4 : Type Checking, Input/Output, and Programming

More information

Supporting Class / C++ Lecture Notes

Supporting Class / C++ Lecture Notes Goal Supporting Class / C++ Lecture Notes You started with an understanding of how to write Java programs. This course is about explaining the path from Java to executing programs. We proceeded in a mostly

More information

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

More information

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures Chapter 5: Procedural abstraction Proper procedures and function procedures Abstraction in programming enables distinction: What a program unit does How a program unit works This enables separation of

More information

Code Generation & Parameter Passing

Code Generation & Parameter Passing Code Generation & Parameter Passing Lecture Outline 1. Allocating temporaries in the activation record Let s optimize our code generator a bit 2. A deeper look into calling sequences Caller/Callee responsibilities

More information

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing

More information

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables

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

Chapter 1: Object-Oriented Programming Using C++

Chapter 1: Object-Oriented Programming Using C++ Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms

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

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information

More information

CSE351 Winter 2016, Final Examination March 16, 2016

CSE351 Winter 2016, Final Examination March 16, 2016 CSE351 Winter 2016, Final Examination March 16, 2016 Please do not turn the page until 2:30. Rules: The exam is closed-book, closed-note, etc. Please stop promptly at 4:20. There are 125 (not 100) points,

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 31 Static Members Welcome to Module 16 of Programming in C++.

More information

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych CS125 : Introduction to Computer Science Lecture Notes #38 and #39 Quicksort c 2005, 2003, 2002, 2000 Jason Zych 1 Lectures 38 and 39 : Quicksort Quicksort is the best sorting algorithm known which is

More information

CS112 Lecture: Defining Instantiable Classes

CS112 Lecture: Defining Instantiable Classes CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:

More information

JAVA: A Primer. By: Amrita Rajagopal

JAVA: A Primer. By: Amrita Rajagopal JAVA: A Primer By: Amrita Rajagopal 1 Some facts about JAVA JAVA is an Object Oriented Programming language (OOP) Everything in Java is an object application-- a Java program that executes independently

More information

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS JAN 28,2011 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 FINALTERM EXAMINATION 14 Feb, 2011 CS304- Object Oriented

More information

A brief introduction to C programming for Java programmers

A brief introduction to C programming for Java programmers A brief introduction to C programming for Java programmers Sven Gestegård Robertz September 2017 There are many similarities between Java and C. The syntax in Java is basically

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical

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

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

CS 6353 Compiler Construction Project Assignments

CS 6353 Compiler Construction Project Assignments CS 6353 Compiler Construction Project Assignments In this project, you need to implement a compiler for a language defined in this handout. The programming language you need to use is C or C++ (and the

More information

4.2 Variations on a Scheme -- Lazy Evaluation

4.2 Variations on a Scheme -- Lazy Evaluation [Go to first, previous, next page; contents; index] 4.2 Variations on a Scheme -- Lazy Evaluation Now that we have an evaluator expressed as a Lisp program, we can experiment with alternative choices in

More information

Typed Racket: Racket with Static Types

Typed Racket: Racket with Static Types Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type

More information

COEN244: Class & function templates

COEN244: Class & function templates COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library

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: 1 Date:

More information

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

Topics Covered Thus Far CMSC 330: Organization of Programming Languages Topics Covered Thus Far CMSC 330: Organization of Programming Languages Names & Binding, Type Systems Programming languages Ruby Ocaml Lambda calculus Syntax specification Regular expressions Context free

More information

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result. Every program uses data, either explicitly or implicitly to arrive at a result. Data in a program is collected into data structures, and is manipulated by algorithms. Algorithms + Data Structures = Programs

More information

6.001 Notes: Section 1.1

6.001 Notes: Section 1.1 6.001 Notes: Section 1.1 Slide 1.1.1 This first thing we need to do is discuss the focus of 6.001. What is this course all about? This seems quite obvious -- this is a course about computer science. But

More information

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including: Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including: Abstraction Encapsulation Inheritance and Polymorphism Object-Oriented

More information

If Statements, For Loops, Functions

If Statements, For Loops, Functions Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements

More information

6.001 Notes: Section 17.5

6.001 Notes: Section 17.5 6.001 Notes: Section 17.5 Slide 17.5.1 Now, let's look at one example in which changing the evaluation model allows us to explore a very different kind of computational problem. Our goal is to show how

More information

CS112 Lecture: Primitive Types, Operators, Strings

CS112 Lecture: Primitive Types, Operators, Strings CS112 Lecture: Primitive Types, Operators, Strings Last revised 1/24/06 Objectives: 1. To explain the fundamental distinction between primitive types and reference types, and to introduce the Java primitive

More information