1 / 11

A variable is just a space in the computer’s memory to store data temporarily.

Variables. A variable is just a space in the computer’s memory to store data temporarily. They are called variables because their values may change throughout the program. Generally variables use sensible names and follow camel case notation

ray
Download Presentation

A variable is just a space in the computer’s memory to store data temporarily.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Variables • A variable is just a space in the computer’s memory to store data temporarily. • They are called variables because their values may change throughout the program. • Generally variables use sensible names and follow camel case notation • Every variable has a scope which defines the life of the variable.

  2. Declaring a variable • int x = 1; (A variable of integer type called x. A value of 1 is assigned) • double y = 1.0; (A variable of double type called y. It has been assigned the value of 1.0)

  3. Arithmetic operators + for addition • for subtraction / for division % known as mod. Used for dividing and returning the remainder.

  4. ‘=‘ Assignment operator • The assignment operator works by evaluating an expression and assigning it to the variable. For example: int total = 10; total = total + 1; (Here we are adding 1 to the existing value of total which was 10, so after adding the total becomes 11)

  5. Data types • A data type is a classification of identifying one of the various types of data, such as real numbers, integer or Boolean. A data type determines the possible values for that type. • For example: • Int – Integer • Double – real numbers • Char – characters

  6. Instance • As you already know that a class provides a blue print for objects and acts like a template for the objects. When an object is created we say it is an instance of a particular class. • E.g. Karel myrobot1 = new Karel; • In the above example we have created an object called myrobot1 from the Karel class. The ‘new’ operator creates an instantiation of a class.

  7. Classes as Hierarchy • Remember you wrote a class which extends Karel and gives you the basic functionality of Karel • And then we extended SuperKarel which gave us even more functions like turnRight Karel SuperKarel Subclass

  8. Super class Karel Super Class Super Karel Sub Class

  9. Classes, objects and instances Animals Digest food Blastula stage Warm Blooded Have memory glands Five fingers Monkeys Highly developed brains Alex & Sam are objects of the human class Object is an instance of a class Alex Sam

  10. The ACM (Association for Computing Machinery) was founded in 1947. It is the largest and oldest international scientific and industrial computer society. Association of Computer Machinery

  11. The “Add2Integers” program

More Related