1. A constructor cannot access ___________.

a) A private instance variable

b) A static variable

c) A local variable defined in other method

d) A public instance variable

2. A compiler error will occur if an instance method in the class  WalletClasstries to access a private data member in WalletClass.

a) depends on how the method uses the object

b) false

c) true

3. If the WalletClass has a private data member called money, and its constructor is public WalletClass(double mon) { money = mon; } what will happen when you try the following code fragment in the main method in another class?

             WalletClass myWallet=new WalletClass(14.00);

            System.out.println( myWallet.money );

a) a zero will be printed

b) The contents of money (14.00) will be printed out

c) it is a compiler error

d) a false will be printed

4) Only one object of any particular class can be instantiated in a main method.

a) false

b) true

c) depends on how the class was written

Source link

Leave a Reply

Your email address will not be published.