DifferenceEasy2 marks
Write a difference between class and an object.
Topic: Class and object
Previous-year question practice database
Answer
Exam answer
The difference is shown in the table.
Explanation
Give one clear difference with an example — the marks are for the distinction, not for length. The everyday analogy that works well: a class is like the architect’s plan of a house, and each house actually built from it is an object. Note the memory point, since it is the technical half of the answer: a class occupies no memory for data, while every object gets its own copy of the instance variables.
Comparison
| Class | Object |
|---|---|
| A blueprint or template that defines the variables and methods common to a group of things; no memory is allocated for it. | An actual instance created from a class using the new keyword; memory is allocated for each object. |
| Declared once, e.g. class Student { ... } | Many can be created from one class, e.g. Student s1 = new Student(); |
More from Class as the Basis of All Computation
Consider the following statements:
Computer desktop = new Computer();
Computer Mainframe = new Computer();
Name the objects of the class given above:2026Define a class named StepTracker with the following specifications:
Member Variables:
String name - stores the user’s name.
int sw - stores the total number of steps walked by the user.
double cb - stores the estimated calories burned by the user.
double km - stores the estimated distance walked in kilometers.
Member Methods:
void accept() - to input the name and the steps walked using Scanner class methods only.
void calculate() - calculates calories burned and distance in km based on steps walked using the following estimation table:
Calories Burned : steps walked x 0.04 (e.g. 1 step burns 0.04 calories)
Distance (Km) : steps walked / 1300 (e.g. 1300 steps is approx. 1 km)
void display() - Display the calories burned, distance in km and the user’s name.
Write a main method to create an object of the class and invoke the methods.2026Which of the following is user defined data type?
1. array
2. double
3. class
4. boolean2025Which of the following is true for the given object creation statement?
Game cricket = new Game();2025Define a class named CloudStorage with the following specifications:
Member Variables:
int acno - stores the user’s account number.
int space - stores the amount of storage space in GB purchased by the user.
double bill - stores the total price to be paid by the user.
Member Methods:
void accept() - prompts the user to input their account number and storage space using Scanner class methods only.
void calculate() - calculates the total price based on the storage space purchased using the pricing table provided:
Storage range Price per GB (Rs)
First 15 GB 15
Next 15 GB 13
Above 30 GB 11
void display() - displays the account number, storage space and bill to be paid.
Write a main method to create an object of the class and invoke the methods of the class with respect to the object.2025Consider the given picture and choose the correct statement from the following:2024