Skip to content

Object Oriented Programming

CSE · Quiz · Spring 25

Paper 3 of 3By Md Alif RabbiSwitch

Paper 3 of 3

This browser can’t show the PDF here

Open it, and your phone’s PDF viewer takes it, or download it.

Read the questions as text

Read off the PDF by AI, so it may have mistakes. The PDF is the original.

Class Test-01 (65_C) CSE 221: Object Oriented Programming (Spring-2025) Name: ID: 1) Read the below code for answering the following question: class DataStore { int dataCount = 75; static int totalRecords = 500; void processData() { int tempValue = 25; System.out.println("Temporary Value: " + tempValue); System.out.println("Data Count: " + dataCount); System.out.println("Total Records: " + totalRecords); } public static void main(String[] args) { DataStore record1 = new DataStore(); DataStore record2 = new DataStore(); record1.dataCount = 100; record2.dataCount = 200; record1.totalRecords = 600; record1.processData(); record2.processData(); } } a) Find out the local variable, instance variable, and static variable in the given program and also explain the reason. (Mark: 03) Local Variable: tempValue (Declared inside processData() method) Instance Variable: dataCount (Declared inside DataStore class but outside any method) Static Variable: totalRecords (Declared inside DataStore class with static keyword) b) Write the expected output of the above program. (Mark: 03) Temporary Value: 25 Data Count: 100 Total Records: 600 Temporary Value: 25 Data Count: 200 Total Records: 600 2) Mr. Alif has run the following program in his computer. But, the compiler showed error in line 27 & 29. Then, he became confused. Then he removed those two lines and run again. Then the program has been executed successfully without any error. Now, read the following code for answering the question. 1. package myPackage; 2. 3. class Account { 4. private double balance = 1000.50; 5. protected String accountType = "Savings"; 6. public String bankName = "Global Bank"; 7. int branchCode = 1234; 8. 9. private void showBalance() { 10. System.out.println("Balance: " + balance); 11. } 12. 13. public void displayDetails() { 14. showBalance(); 15. System.out.println("Account Type: " + accountType); 16. System.out.println("Bank Name: " + bankName); 17. System.out.println("Branch Code: " + branchCode); 18. } 19. } 20. 21. public class Bank { 22. public static void main(String[] args) { 23. Account acc = new Account(); 24. System.out.println("Bank Name: " + acc.bankName); 25. System.out.println("Account Type: " + acc.accountType); 26. System.out.println("Branch Code: " + acc.branchCode); 27. System.out.println("Balance: " + acc.balance); 28. acc.displayDetails(); 29. acc.showBalance(); 30. } 31. } a) Explain the reason of the showing error in line 27 & 29. (Mark: 02) Line 27 balance is declared as private. Line 29 showBalance() method is declared as private. b) Write the output the above code after removing line 27 & 29. (Mark: 03) Bank Name: Global Bank Account Type: Savings Branch Code: 1234 Balance: $1000.5 Account Type: Savings Bank Name: Global Bank Branch Code: 1234 c) Give the "✓ /Yes" or, "✕ / No" in the below index according to the column-wise conditions for the given Variable/Method. (Mark: 04) Variable/Method | Same Class | Same Package | Subclass (Diff. Package) | Non-Subclass (Diff. Package) balance | ✓ | ✕ | ✕ | ✕ accountType | ✓ | ✓ | ✓ | ✕ bankName | ✓ | ✓ | ✓ | ✓ branchCode | ✓ | ✓ | ✕ | ✕