Questions and answers –
Some of the answers to the questions given below require examples. Remember, whether it asked
or not, giving an example with the answer (where it is possible) is mandatory to score cent percent
marks.
Q1. What is object-oriented programming?
Ans. In object-oriented programming, the data required for the program is divided and stored into
restricted, independent and discrete area of computer memory called object which can be accessed
directly, only by certain specific procedures defined in class to which the object belong to. The data of an
object cannot be accessed directly by procedures of other class’ objects. However, the data of one object
can be accessed indirectly by invoking or calling its procedures by procedures of other class’ object. To
make an application run, objects of different classes call or invoke one another’s procedures.
Q2. What do you mean by sending or passing messages?
Ans. The objects of different classes collaborate and interact by sending or passing messages to one
another. To make an application run, objects of different classes call or invoke one another’s procedures.
Q3. What are the four OOP principles? Explain each of them.
Ans. The four OOP principles are encapsulation, abstraction, inheritance and polymorphism.
Encapsulation:
Encapsulation is the characteristic that data in an object can be accessed only by the method or code that
is defined in its class. This mechanism keeps both data and code safe from outside interference and
misuse. This is achieved by bundling data and code in the class.
Abstraction:
Abstraction is a concept of hiding unnecessary details and representing only the very essential features.
Abstraction permits the programmer to look at something without being concerned with the internal
details.
Inheritance:
Inheritance is the process of creating new class, called subclass (also called derived class, extended class
or child class), from existing class called the superclass (also called base class or parent class). The
subclass inherits fields and methods of the superclass but can add new fields and methods of its own.
Polymorphism:
The ability of an object to respond, each in its own way, to identical methods calls is called polymorphism.
, Method overloading and method overriding are two of the ways that Java implements polymorphism.
This can only happen when there is parent and child relationship between classes using inheritance.
Q4. Give at least one way as to how Java implements functional abstraction.
Ans. Java implements functional abstraction through methods in a class.
Q5. What do mean by subclass and super class?
Ans. A class that is derived from another class is called a subclass. The class from which the subclass is
derived is called a superclass.
Q6. Give an advantage of inheritance in Java.
Ans. Inheritance permits code reusability. Reusing existing code reduces program-development time,
increases program’s reliability and saves money.
Q7. How is polymorphism implemented in Java?
Ans. Method overloading is one of the ways that Java implements polymorphism.
Q8. What do you mean by data hiding?
Ans. Protecting objects’ instance variables from direct access by methods outside the class is called data
hiding.
Q9. Give the general definition of class and its object.
Ans. In real world a class defines the properties (or characteristics or attributes or state) and behaviour
that will be shared by a set of objects. Each object of a class contains the properties and exhibits the
behaviour defined by the class. From programming point of view, an object stores its properties in
instance variables and exposes its behaviour through methods.
Q10. What is the difference between a class and its object from programming point of view?
Ans. A class is a template, model, or blueprint for its objects. A class defines the data required for the
program and certain specific codes that can directly access that data. The data required for the program
is divided and stored into restricted, independent and discrete area of computer memory called object
which can be accessed directly, only by certain specific codes defined in class to which the object belong
to. The variables defined within a class may be instance variables or static variables or both, collectively
called fields. The code is contained within methods.
Q11. What do you mean by members of the class?
Ans. Fields (instance variables and static variables) and methods defined within a class are called
members of the class.