Class Variables - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Class Variables

Description:

Do not belong to individual objects. Belong to all objects ... name = 'B Inge' strtNum = '768' strtName = 'Oak' zipCode = 43556. Class Methods. Class Methods ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 9
Provided by: jacobh
Category:
Tags: class | inge | variables

less

Transcript and Presenter's Notes

Title: Class Variables


1
Class Variables Class Methods
  • private static int numObjectsCreated
  • public static void getNumObjects()

2
Class Variables
  • Class Variables
  • Also called static fields
  • Defined in the class
  • Do not belong to individual objects
  • Belong to all objects
  • All BankAccounts share numberOfAccounts
  • Instance Variables
  • Each object gets its own variable.
  • Each BankAccount has its own balance

3
Example
  • public class Client
  • private String name, streetNum, streetName,
    city
  • private int zipCode, acctNum
  • private double balanceOwed
  • private static int numClients 0
  • private static double totalClientRevenue 0.0
  • private static String state CA
  • / This example assumes all clients live in
    California. /

4
(No Transcript)
5
Class Methods
  • Class Methods
  • Perform from the class
  • Do not perform on individual objects
  • Syntax is
  • ClassName.methodName()
  • Instance Methods
  • Perform on an object
  • Syntax is
  • objRef.methodName()

6
Example
  • public class Client
  • public double getBalance() return balance
  • public String getStrtNum() return strtNum
  • public static int getNumClients()
  • return numClients
  • public static double getTotalRevenue()
  • return totalClientRevenue
  • public static String getState()
  • return state
  • public static void updateAllAccounts()

7
(No Transcript)
8
Example
  • public class ClientClient
  • Client c1 new Client()
  • String c1Adress c1.getStreetNum()
    c1.getStreetName() \n
  • c1.getCity() ,
  • Client.getState()
  • double totalRevenue Client.getTotalRevenue()
  • int numClients Client.getNumClients()
Write a Comment
User Comments (0)
About PowerShow.com