Classes:%20user-defined%20types - PowerPoint PPT Presentation

About This Presentation
Title:

Classes:%20user-defined%20types

Description:

Classes: user-defined types Organizing method with a class A class is used to organize methods * Methods that compute Mathematical functions * The Scanner ... – PowerPoint PPT presentation

Number of Views:174
Avg rating:3.0/5.0
Slides: 18
Provided by: cheng176
Category:

less

Transcript and Presenter's Notes

Title: Classes:%20user-defined%20types


1
Classes user-defined types
2
Organizing method with a class
  • A class is used to organize methods
  • Methods that compute Mathematical functions 
  • The Scanner class

3
Organizing information with a class
  • A class can also be used to organize information
  • It defines a group of related information that
    belong to the same entity

4
Instance Variables (1)
  • Java has 4 different kinds of variables
  • 1. Local variables
  • 2. Parameter variables

5
Instance Variables (2)
3. Class variables
6
Instance Variables (3)
  • 4. Instance variables 
  • are defined inside some class
  • are defined outside every method of that class.
  • are defined without using the keyword static

7
Creating an object in Java (1)
  • Define a variable to store the location of
    the object.
  • Create the object

8
Creating an object in Java (1)
9
Creating an object in Java (2)
10
Accessing the information stored inside an object
(1)
11
Accessing the information stored inside an object
(2)
12
Accessibility rule for instance variables
  • The accessibility of instance variables are
    controlled by access modifiers 
  • public   can be accessed in a method
    inside any class
  • private  can be accessed  in a method
    inside the same class

13
Lifetime of Instance variables (1)
14
Lifetime of Instance variables (2)
These instance variables will cease to
exist after the garbage collection
procedure has completed execution
15
Methods using a object variable as parameter (1)
  • A class in Java is equivalent to a data type

16
Methods using a object variable as parameter (2)
  • Variable x and variable stu1 will access
    the same memory locations

17
Changing the values of a variable inside an object
Write a Comment
User Comments (0)
About PowerShow.com