121k views
5 votes
If you have defined a class named SavingsAccount with a public static data member named numberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts?

A) numAccounts = SavingsAccount.numberOfAccoun ts;B) numAccounts = numberOfAccounts;C) numAccounts = account20.numberOfAccounts;D) None of the above, you cannot reference a static data member.

1 Answer

2 votes

Answer:

numAccounts = SavingsAccount.numberOfAccounts

Step-by-step explanation:

In object oriented programming, when you have created an object of class, you can create several instances (objects) from that class by referencing the className.classFeild. In this instance SavingsAccount is the class name and

numberOfAccounts is a feild (or data member). to create a new numAccount, we use the syntax as above in the answer

User Joachim VR
by
5.7k points