Static vs Instance Variables
Develop code to declare the class variables that belong to the class.
Consider this partial class definition:
public class BankAccount {
private double balance;
private static double interestRate;
private static int nextAccountNumber = 1000;
// constructor and methods not shown
}
Which statement about these variable declarations is correct?
A
All three variables are accessible from static methods without creating an object instance
B
nextAccountNumber should be declared as an instance variable since each account needs a unique number
C
interestRate and nextAccountNumber are shared by all BankAccount objects, while balance is unique to each object
D
balance and interestRate are instance variables, while nextAccountNumber is a class variable
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | Ishaan.m.kurup | 2 | 5 | 0m 00s | 170 |
| #2 | songqiuhui2012 | 2 | 2 | 0m 32s | 168 |
| #3 | sailajavadlamani33 | 1 | 1 | 0m 00s | 100 |
| #4 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #5 | y.seong2027 | 0 | 1 | 1m 36s | -106 |
| #6 | suhanakochhar006 | 1 | 4 | 7m 34s | -384 |
APFIVE