Course Content‎ > ‎Session 4‎ > ‎

Exercises

Answer the questions given below
 
1. Java is a true object-oriented programming language.(True / False)
 
2. Everything in a Java program must be encapsulated in a class. (True/False)
 
3. Class serves as a template for making ...........................
 
4. Can an object be created without using new operator. (Yes / No)
 
5.  The whole Java program, is organized into classes.  (True / False)
 
6. The memory space is allocated for an object, when it is  ..........................
 
7. Classes allow ........................ of data.
 
8. Can we create a class with only data items and no methods in it? (Yes / No)
 
9. Inheritance allows us to reduce the code. (True / False)
 
10. Is constructor a method? (Yes / No)
 
11. Constructors do not return any value (True / False)
 
12. Constructor is invoked whenever the ..............  of that class is created.
 
13. Static variables and methods are common to all the objects of a class
 
14. Static methods can be called either by using the ...................................... or ............................
 
15. If value of a class variable is changed, it will be reflected in all the objects of that class. (Yes / No)
 
16. If a method does not return a value, what should the method type be?
 
17. Which of the following is a valid full constructor header for the class circle with data members int color and float
radius?
 
a.  circle();
b.  circle(int c, float r);
c.  circle(double c, char r);
d.  circle(String c);
 
18. Design a class to represent a bank account. Include the following members:
 
a. Data members
b. Name of the Depositor
c. Account Number
d. Type of the Account
e. Balance amount in the account
f. Methods
g. To assign initial values
h. To deposit an amount
i. To withdraw an amount after checking balance
j. To display the name and balance.

Write a main program to test the program.
 
19. Modify the above question to incorporate a constructor to provide initial values.
 
20. Write a program, which calculates commission of salesperson. The data fields for the SalesPerson class are name,
weekly sales, commission rate and commission due.This program should accept the input for name, weekly sales and
commission rate and should display the commission due.
 
21. Write a program, which writes invoices for a repair shop. The data fields for the Repair class are worker's name,
number of hours, hourly rate, cost of parts and total job cost. The program should accept the require input and calculate
and display the total job cost.

Comments