Class as Basis of All Computation

ICSE Class 10 Computer Applications · Sumita Arora Computer Applications · 44 solved questions

Exercise
1Objective Type Questions

An object is an identifiable entity with some characteristics and behaviour.

Solution not available in the source paper.

2Objective Type Questions

Abstraction refers to the act of representing essential features without including the background details or explanations.

Solution not available in the source paper.

3Objective Type Questions

Encapsulation is the way of combining both data and the functions that operate on that data under a single unit.

Solution not available in the source paper.

4Objective Type Questions

Object can be defined as a software bundle of variables and related methods.

Solution not available in the source paper.

5Objective Type Questions

Real world objects encapsulate characteristics and behaviour.

Solution not available in the source paper.

6Objective Type Questions

Objects interact with one another through messages.

Solution not available in the source paper.

7Objective Type Questions

The data in an object is accessed through the member functions of the object known as methods.

Solution not available in the source paper.

8Objective Type Questions

The real world objects are implemented in software form by representing their state through variables or data items called member variables.

Solution not available in the source paper.

9Objective Type Questions

The behaviour of the object is represented through functions called methods.

Solution not available in the source paper.

10Objective Type Questions

The values of data member or member variables at any given point of time determine an object's state.

Solution not available in the source paper.

11Objective Type Questions

A class is a blueprint of set of objects that have a common structure and common behaviour.

Solution not available in the source paper.

12Objective Type Questions

An object is identified by its attributes.

Solution not available in the source paper.

13Objective Type Questions

In Object Oriented Programming, objects are defined by defining a class for them.

Solution not available in the source paper.

14Objective Type Questions

A class is a named software representation for an abstraction.

Solution not available in the source paper.

15Objective Type Questions

The class is an object maker or object factory.

Solution not available in the source paper.

16Objective Type Questions

A class basically represents an abstraction of an object.

Solution not available in the source paper.

17Objective Type Questions

In software terms, an entity's characteristics are represented through data members.

Solution not available in the source paper.

18Objective Type Questions

There can be multiple classes representing different abstractions of an object.

Solution not available in the source paper.

19Objective Type Questions

Static or class variables are created once for entire class and are shared by all the objects. [(a) static or class variables (b) Instance variables (c) shared variable (d) none of the above]

Solution not available in the source paper.

1Assignment Questions

What is an object ? Give examples of some real world objects.

Show SolutionHide Solution↓

An object is an entity having a specific identity, specific characteristics and specific behaviour.

Examples:

  1. A car is an object.
    Characteristics — It has colour, length, width, height, model, a steering wheel, gear box etc.
    Behaviour — Accelerating, changing gears, braking, etc.
  2. A book is an object.
    Characteristics — It has a name, ISBN number, author, publisher, price, etc.
    Behaviour — Book can be read, opened/closed, borrowed/returned, etc.
  3. A student is an object.
    Characteristics — It has a name, age, address, class, section, subjects etc.
    Behaviour — He/she can study, play, sleep.
3Assignment Questions

Define data abstraction.

Show SolutionHide Solution↓

Abstraction refers to the act of representing essential features without including the back­ ground details or explanations.

4Assignment Questions

Define Encapsulation.

Show SolutionHide Solution↓

The wrapping up of data (characteristics) and functions (behaviour) into a single unit, called class, is known as Encapsulation. It is a way to implement data abstraction.

5Assignment Questions

What is message passing among objects ?

Show SolutionHide Solution↓

When the objects need to interact with one another, they pass/request information to/from one-another. This interaction is known as message passing. Objects interact with one another through messages.

6Assignment Questions

What are methods ? What do they represent ?

Show SolutionHide Solution↓

The behaviour of an object is described through associated functions called methods. In object oriented programming, the state of an object can only be accessed through its associated methods.

Methods represent the behaviour of an object.

7Assignment Questions

What is information hiding ?

Show SolutionHide Solution↓

Information hiding is the process of hiding all the secrets of an object that do not contribute to its essential characteristics. The structure of an object is hidden, as well as the implementation of its methods. Only the essential characteristics of object are visible.

8Assignment Questions

What is a method ? Can there be objects without having any methods ?

Show SolutionHide Solution↓

The behaviour of an object is described through associated functions called methods.

In Java, every class is a subclass of Object class and so, all objects inherit the methods of the Object class. Thus, it is not possible for objects to be without any methods.

9Assignment Questions

What is a class ?

Show SolutionHide Solution↓

A class is a blueprint of a set of objects that have a common structure and common behaviour.

10Assignment Questions

What is an abstraction ? Can there be multiple abstractions of a real-world entity ?

Show SolutionHide Solution↓

Abstraction refers to the act of representing essential features without including the back­ ground details or explanations.

Yes, there can be be multiple abstractions of a real-world entity because abstraction is always relative to the purpose or user.

For instance, if we consider a student, we can talk of anything that belongs to her in the real world like her name, family, parents' profession, locality she lives in, marks obtained by her, her roll-number in the class, her medical history, her talents, her awards etc. But when we talk of a student result tracking system, the abstraction for it would be her roll-no, name, marks obtained etc. For extra-curricular activities, the abstraction would be her roll-no, talents and awards.

11Assignment Questions

How are classes and abstraction linked ?

Show SolutionHide Solution↓

A class is a named software representation for an abstraction. A class actually represents an abstraction, where characteristics are implemented through data and behaviour is implemented through methods.

For example, the abstract concept of a car can be represented in the program by a class with properties like make, model, and year, and methods like start() and stop().

12Assignment Questions

How do you map an abstraction into software ?

Show SolutionHide Solution↓

We map an abstraction into software form by depicting all its physical characteristics through data items and all its functionality i.e., behaviour through functions which are called methods.

How do you map an abstraction into software ? Class as Basis of all Computation, Sumita Arora Computer Applications Solutions ICSE Class 10

Thus, in an object:

  1. there are variables to hold data, called member variables.
  2. the values of these member variables define the state of an object.
  3. there are member functions/operations/methods that define the behaviour of objects.
13Assignment Questions

How are real world objects implemented/represented in software terms ?

Show SolutionHide Solution↓

The object is implemented in software terms as follows :

  1. Characteristics/attributes are implemented through member variables or data items of the object.
  2. Behaviour is implemented through member functions called methods.
  3. Data and methods are encapsulated into one unit and given a unique name to give it identity.

Thus, a real world object is represented in software terms as a software bundle of variables and related methods.

14Assignment Questions

How is data abstraction associated with encapsulation ?

Show SolutionHide Solution↓

Abstraction and encapsulation are complementary concepts. Abstraction focuses upon the observable behaviour of an object, whereas encapsulation focuses upon the implemen­tation that gives rise to this behaviour. Encapsulation is most often achieved through information hiding, which is the process of hiding all the secrets of an object that do not contribute to its essential characteristics, the structure of an object is hidden, as well as the implementation of its methods. Only the essential characteristics of object are visible.

Thus, encapsulation is a way to implement data abstraction. Encapsulation hides the details of the implementation of an object.

15Assignment Questions

'There can be many abstractions of an object'. Comment.

Show SolutionHide Solution↓

There can be many classes defined for an entity, for a class represents an abstraction. An abstraction is always relative to the purpose or user.

For instance, if we talk of a student, we can talk of anything that belongs to her in the real world like her name, family, address, marks obtained by her, her roll-number in the class, her medical history, her talents, her awards etc. But when we talk of a student result tracking system, the abstraction for it would be - her roll_no, name, marks obtained etc. For extra-curricular activities, the abstraction would be - her roll_no, talents and awards.

Thus, there can be many abstractions of an object.

16Assignment Questions

How does object encapsulate its state and behaviour ?

Show SolutionHide Solution↓

An object stores its state in member variables and exposes its behaviour through the member methods. The member methods operate on member variables and serve as the primary mechanism to interact with the object. Only the member methods which are wrapped inside the class can access the data and change its state.

Hence, the state and behaviour are said to be encapsulated by the object, hiding internal state and requiring all interaction to be performed through the methods of the object.

17Assignment Questions

How do objects interact with one another? Give an example.

Show SolutionHide Solution↓

When the objects need to interact with one another, they pass/request information to/from one-another. This interaction is known as message passing. Objects interact with one another through messages.

For instance, to represent a school's working, we can represent its various units — admission desk, fee department, enquiry desk, academic department, activities department, transport department etc.

Now, let us consider a new student who wants admission in the school. Here, the admission desk will get the details of the student and direct him to fee department to deposit the fee, which will require the admission desk and fee department to communicate regarding the amount of fee to be paid by the student. This communication takes place through message passing.

18Assignment Questions

Why are classes needed ?

Show SolutionHide Solution↓

In Java, the class forms the basis of all computation. A class is a blueprint for an object and an object is an instance of a class. It allows a programmer to define all of the properties and methods that define an object.

Anything that has to exist as a part of a Java program has to exist as a part of a class, whether that is a variable or a function or any other code-fragment. Without classes, there can be no objects and without objects, no computation can take place in Java. Thus, classes form the basis of all computation in Java.

20Assignment Questions

Can there be multiple classes for the complete representation of a real world entity ? Give examples.

Show SolutionHide Solution↓

Yes, there can be multiple classes for the complete representation of a real world entity.

For example, let us consider a school. A school has multiple units to perform different functions — enquiry/admission desk, fee counter, academic board, activities board, sports board, student help desk, etc. All these units work in conjunction for the efficient working of the school. Now, each unit can be treated as a different class which has required member variables and methods to perform their tasks.

21Assignment Questions

Why are classes said to be abstractions of or a set of objects ?

Show SolutionHide Solution↓

A class is a blueprint of a set of objects that have a common structure and behaviour. Once a class is defined, any number of objects can be created. All the objects have common attributes and behaviour. Thus, classes are said to be abstractions of or a set of objects. We can think of a class as a cookie cutter and an object as an actual cookie.

22Assignment Questions

Why are objects said to be instances of a class ?

Show SolutionHide Solution↓

A class represents a blueprint based on which actual memory is allocated for data members and methods of a class and it is called an object. So an object gets its own copy of data members and methods based on class details. Hence, objects are said to be instances of a class.

23Assignment Questions

Consider the following code fragment assuming that a class namely Student has been defined earlier :

Student stud1;

What is above statement doing ?

Show SolutionHide Solution↓

The given statement declares a variable stud1 of type Student. It will be used to refer to a Student object. stud1 is a null reference.

24Assignment Questions

How is following statement different from statement given in previous question ?
Student stud1 = new Student( );

Show SolutionHide Solution↓

The statement Student stud1; only declared a variable stud1 of type Student.

The statement Student stud1 = new Student( ); not only declares a variable but it actually instantiates the object stud1 of class Student by using the 'new' keyword.

25Assignment Questions

Write a program to accept a number and check and display whether it is a spy number or not. (A number is spy if the sum of its digits equal the product of its digits.)
Example : Consider the number 1124,
Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1 x 1 x 2 x 4 = 8.

Show SolutionHide Solution↓
import java.util.Scanner;

public class KboatSpyNumber
{
    public static void main(String args[]) {
        
        Scanner in = new Scanner(System.in);
        
        System.out.print("Enter Number: ");
        int num = in.nextInt();
        
        int digit, sum = 0;
        int orgNum = num;
        int prod = 1;
        
        while (num > 0) {
            digit = num % 10;
            
            sum += digit;
            prod *= digit;
            num /= 10;
        }
        
        if (sum == prod)
            System.out.println(orgNum + " is Spy Number");
        else
            System.out.println(orgNum + " is not Spy Number");
        
    }
}
BlueJ output of KboatSpyNumber.java

Press ↓ to reveal a solution and move to the next question. Back to Sumita Arora Computer Applications.

Free sample bank