Page: 5
2. Declarations and Access Control
Q: 19 Click the Task button.  Solution: public class Single{ private static Single instance; public static Single getInstance( ){ if(instance==null) instance = create( ); return instance; } protectedSingle( ) { } staticSingle create ( ) { return new Single ( ) ; } } class SingleSub extends Shape{ } Q: 20 Given: 12. public class Test { 13. public enum Dogs {collie, harrier}; 14. public static void main(String [] args) { 15. Dogs myDog = Dogs.collie; 16. switch (myDog) { 17. case collie: 18. System.out.print("collie "); 19. case harrier: 20. System.out.print("harrier "); 21. } 22. } 23. } What is the result? A. collie B. harrier C. Compilation fails. D. collie harrier E. An exception is thrown at runtime. Answer: D Q: 21 Click the Exhibit button. Given: ClassA a = new ClassA(); a.methodA(); What is the result?  A. Compilation fails. B. ClassC is displayed. C. The code runs with no output. D. An exception is thrown at runtime. Answer: D Q: 22 Click the Task button.  Solution: public int update(int quantity,int adjust){ quantity=quantity+adjust; return quantity; } public void call Update( ) { int quant=100; quant=update(quant,320); System.out.println("the quantity is " +quant); }
Page: 5
1
2
3
4
5
6
|