Static vs Instance Variables
Consider the following partial class definition.
public class BankAccount {
private double balance;
private static double interestRate;
private static int nextAccountNumber = 1000;
// constructor and methods not shown
}
Which of the following statements about these variable declarations is correct?
A
nextAccountNumber should be declared as an instance variable since each account needs a unique number
B
All three variables are accessible from static methods without creating an object instance
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 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #4 | sailajavadlamani33 | 1 | 1 | 0m 00s | 100 |
| #5 | y.seong2027 | 0 | 1 | 1m 36s | -106 |
| #6 | suhanakochhar006 | 1 | 4 | 7m 34s | -384 |
| #7 | bommasam000 | 2 | 4 | 15m 14s | -734 |
Items per page:
10
1 – 7 of 7
APFIVE