Chapter 2: Elementary Concept of Object and Classes

PrevNextBack

Chapter 2: Elementary Concept of Object and Classes

Contents

Fill in the blanks

Question 1

A Class is also considered as an object factory.

Question 2

The Object of a class differs on various characteristics.

Question 3

The object of a class is represented through the attributes.

Question 4

The term instantiation is used for creating various objects.

Question 5

Class is a blueprint of the objects.

Question 6

new keyword indicates an operator for dynamic allocation of an object.

Question 7

Objects are also termed as class tags or entities.

Question 8

Different objects of a class have common behaviour.

Answer the following questions

Question 1

Define Object with an example.

Answer

An object is an entity having a specific identity, specific characteristics and specific behavior. Taking a car as an example of an object, it has characteristics like colour, model, version, registration number, etc. It has behaviours like start the engine, stop the engine, accelerate the car, apply the brakes, etc.

Question 2

Mention five states (characteristics) and two methods for the following Classes:

(a) Class Employee

Answer

CharacteristicsMethods
NamecomputeSalary()
Employee NumbercomputeTax()
Pan Number 
Salary 
Income Tax 

(b) Class Bank

Answer

CharacteristicsMethods
Bank NameopenAccount()
Bank AddressdepositMoney()
IFSC Code
MICR Code
Accounts

(c) Class School

Answer

CharacteristicsMethods
School NameadmitStudent()
School AddressconductExams()
Classes
Students
Teachers

(d) Class Book

Answer

CharacteristicsMethods
Book NamebuyBook()
ISBN NumberreadBook()
Price
Author
Publisher

(e) Class Park

Answer

CharacteristicsMethods
Park NameopenPark()
Park AddressclosePark()
Ticket Price
Opening Time
Closing Time

(f) Class Medicine

Answer

CharacteristicsMethods
NamebuyMedicine()
QuantitysellMedicine()
Manufacturing Date
Expiry Date
Price

(g) Class Computer

Answer

CharacteristicsMethods
ModelstartComputer()
Serial NumbershutdownComputer()
Processor
RAM
Hard Disk

(h) Class Camera

Answer

CharacteristicsMethods
ModeltakePicture()
Serial NumberadjustZoom()
Colour
Price
Resolution

Question 3

What is an Object? Give five examples of real world objects.

Answer

An object is an entity having a specific identity, specific characteristics and specific behavior. Examples — car, bottle, mobile phone, computer, student.

Question 4

How will you define a software object?

Answer

A software object replaces the characteristics and behaviours of a real world object with data members and member methods, respectively.

Question 5

Class and Objects are inter-related. Explain.

Answer

A Class is used to create various Objects that have different characteristics and common behaviours. Each object follows all the features defined within a class. That is why class is also referred to as a blue print or prototype of an object. This way we can say that they are inter-related.

Question 6

A class is also referred as 'Object Factory'. Comment.

Answer

A class has the complete description of the data elements the object will contain, the methods the object can do, the way these data elements and methods can be accessed. A class can create objects of itself with different characteristics and common behaviour just like a factory can produce similar items based on a particular design. Hence, class is also referred to as 'Object Factory'.

Question 7

What does the following statement mean?
Employee staff = new Employee ( );

Answer

This statement creates a new object of class Employee. The newly created object is assigned to a variable named staff which is of Employee type. The object can be accessed using staff variable.

Question 8

Why is an Object called an 'Instance' of a class? Explain.

Answer

A class can create objects of itself with different characteristics and common behaviour. So, we can say that an Object represents a specific state of the class. For these reasons, an Object is called an Instance of a Class.

Question 9

Why is a class known as composite data type?

Answer

A class can contain data members of various primitive and reference data types. Hence, class is known as composite data type.

Question 10

Write a statement to create an object 'Keyboard' of the class 'Computer'.

Answer

Computer Keyboard = new Computer();

Question 11

Consider a real world object as 'Cricket Ball'. Now, mention two behaviours and methods each by taking the 'Cricket Ball' as a software Object.

Answer

Characteristics — Colour, Condition
Behaviours/Methods — throw(), stop()

Question 12

Refer a class structure as shown below:

  class MySchool {
     Name
     Address
     Principal's name
     AcceptData();
     PrintData();
  }

With reference to the above class declaration, indicate whether the following statements are True/False:

  1. Acceptdata( ) is the characteristic of the class.
    False

  2. Address is behaviour of the class.
    False

  3. Acceptdata( ) and PrintData( ) are the common behaviour of the objects of class 'MySchool'.
    True

  4. Behaviours are the medium of inter-object communication.
    True

  5. Creating multiple objects of class 'MySchool' is not possible.
    False

Question 13

You want to create a class 'Football'. Choose the elements to be used as characteristics and behavior from the list given below:
Ball, Goalkeeper, Making a goal, Defender, Forward player, passing ball, Referee, hitting corner, making fault

Answer

CharacteristicsBehaviours
BallMaking a goal
Goalkeeperpassing ball
Defenderhitting corner
Forward playermaking fault
Referee

Question 14

Write a program by using a class 'Picnic' without any data members but having only functions as per the specifications given below:
class name : Picnic
void display1( ): To print venue, place and reporting time.
void display2( ): To print number of students, name of the teacher accompanying and bus number.
Write a main class to create an object of the class 'Picnic' and call the functions display1() and display2( ).

Answer

class Picnic
{
    public void display1() {
        System.out.println("Venue: Botanical Garden");
        System.out.println("Place: MG Road");
        System.out.println("Reporting Time: 9:00 AM");
    }
    
    public void display2() {
        System.out.println("Number of Students: 50");
        System.out.println("Name of teacher: Mr. Nagabhushan");
        System.out.println("Bus Number: KA 01 1234");
    }
    
    public static void main(String args[]) {
        Picnic obj = new Picnic();
        obj.display1();
        obj.display2();
    }
}

Video Explanations