Creating Your Own Class - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Creating Your Own Class

Description:

Identifier is a string of characters that names a class. Class names are ... Camel case notation used to name many identifiers. Example of Camel Case Notation ... – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 12
Provided by: winds4
Category:
Tags: camel | class | creating

less

Transcript and Presenter's Notes

Title: Creating Your Own Class


1
Creating Your Own Class
  • Chapter 3 Section 2

2
Identifiers
  • Identifier is a string of characters that names a
    class
  • Class names are called identifiers
  • Identifiers also used to name
  • Methods
  • Fields

3
Camel Case Notation
  • Java is case sensitive
  • Camel case notation used to name many identifiers
  • Example of Camel Case Notation
  • myVariableName

4
Class Fields
  • Class fields-
  • contain data that refer to the state of the
    object
  • Are constituent parts of the class
  • May also be called member variables or class
    variables
  • Field names should be self explanatory

5
Type
  • Class field has a type
  • Type can be
  • intrinsic (built in)
  • User defined
  • User defined must be declared

6
Example of a Type
  • class Student
  • intAge
  • Keyword int declares the member variable age
    There are eight intrinsic types in Java

7
Java Library
  • The Java library is a collection of classes
  • Can help you create member variables
  • Example
  • class Student
  • intAge
  • string Name

8
String
  • String is a class defined in the Java Library
  • Used to hold a string of characters
  • Used with quotes
  • NameJoe Smith
  • Assigning a value to the variable name

9
User Defined Types
  • User defined types is a class the programmer
    defines
  • Example
  • class Tutor
  • String name // name of the tutor
  • Student pupil //the student being tutored

10
Keeping Data Private
  • Declare the member variable with the keyword
    private
  • class Dog
  • private int age
  • private int weight
  • private String name
  • Keyword private means members are visible only to
    Methods found in class Dog

11
Retrieve Data
  • To retrieve data on age
  • Use
  • get.Age() method
  • Reveals age of dog without telling client class
    how age is stored
  • Private and Public are both called access
    modifiers
  • Remember
  • Private means data is only visible to class in
    which it was declared
  • Public is available to all classes in application
Write a Comment
User Comments (0)
About PowerShow.com