03-variables-expressions

03-variables-expressions - Working With Data: Variables and...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Working With Data: Variables and Expressions CSE 114: Computer Science I 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Anatomy of a Class A class contains two types of elements: Instance data — variables that represent the information held by that class Instance methods — methods (code) that deFne what a class can do A given class does not have to contain both elements A class may contain only data, or only methods Each class is deFned using the Java keyword “class” Curly braces enclose the data and method declarations that make up the class 2
Background image of page 2
Class Defnition Example class Example // defnes a new class called “Example” { instance variable declarations go here. .. instance method defnitions go here. .. } 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Variables Variables are the “nouns” of a program They represent pieces of information Different types for different kinds of data: int stores integers char stores single characters (‘a’) Foat and double store decimal values String stores character sequences 4
Background image of page 4
Declarations Java requires you to declare a variable before you use it This tells Java what behavior to expect from that variable Declare a variable (tell the compiler that you’re going to use it)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

03-variables-expressions - Working With Data: Variables and...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online