You are on page 1of 5

RYAN INTERNATIONAL SCHOOL, KHARGHAR

COMPUTER APPLICATIONS

STD: IX
CHAPTER 3 – ELEMENTARY CONCEPTS OF OBJECTS AND CLASSES
DATE: 18/06/2021

NOTES:

PART I : FILL IN THE BLANKS.


1) Objects share three characteristics identity, state and behaviour.
2) A model is a simplification of reality.
3) A model is a complete description of a system from a particular perspective.
4) In object oriented terminology a particular object is called Instance.
5) A object is a software bundle of variables and related methods.
6) Message are used for software objects to interact and communicate with each
other.
7) A prototype of an object is called class.
8) A methods is a subprogram that acts on data and often returns a value.
9) A collection of predefined methods is called method library or library methods.
10) User defined methods are defined by a user. They can be static method
or instance method.
11) If a method is not clearly defined as static, it is instance method.
12) String concatenation can be archieved by + symbol.

PART II : SHORT ANSWER TYPE QUESTIONS:


1) Give two reasons why we model real world entities and their behaviour.
ANS:
• A model is a simplification of reality. We model because we cannot
comprehend the complexity in its entirety.
• We model to visual, specify, construct, and document the structure and
behaviour of a system’s architecture.
• A model is a complete description of a system from a single perspective.
2) What are instance variables?
ANS:
A variable which is declared inside a class but outside any of the method is called
instance variable.

3) What do you understand by attributes of an object?


ANS:
Attributes of an object are Identity, state and behaviour.
• Identity: name given to the object, like name given to a dog or stereo’s
model number.
• State : A dog has state (name, colour, breed).
Stereo has state (colour, switch buttons, motor)
• Behaviours: A dog has behaviours (barking, fetching, wagging tail)
Stereo has behaviours (playing tape, rewinding, fast forwarding)

4) With the help of an example explain “what is a message in a software


application?”
ANS:
Software objects interact and communicate with each other using messages
When object A wants object B to perform one of B’s methods, object A sends
message to object B.

5) How do you differentiate between a class and an object?


ANS:
Class Object

• Class is a blueprint or template • Object is an instance of a class.


from which objects are created.

• Class has logical existence. • Object has physical existence.

• For class, memory space is not • In case of an object memory space


allocated, when it is created. is allocated, when it is created.

• Class is declared once. • Object is created many times.

• Class is declared using the • Object is created through the


keyword ‘class’. keyword ‘new’.
6) Name the main parts of a class.
ANS:
Atrributes / Fields, Constructors and behaviours.

7) How a class is a user defined data type?


ANS:
• Attributes or Fields or Member Variables : They are the properties of an
object of the class. There is a type associated with each field. The type
constrains the type of values that the field can store. A type is a set of values
with operations defined on those values.
• Constructor(s) :A constructor is used to create objects of a class.
• Behaviour or Public Interface or Functions : They are a set of operations
functions or methods, which can be invoked on an object.

8) What is method? List the two types of methods.


ANS:
A method is a subprogram that acts on data and often returns a value.
TYPES OF METHODS :
• Predefined Methods
• User Defined Methods

9) What are predefined methods? Give an example.


ANS:
They are built-in Java and come along with Java Class Library in a Java archive
(.jar) file with JVM and JRE.
Example : sqrt()

10) What do you understand by static methods? Give an example.


ANS:
It is a method that can be called and executed without creating an object. Static
method can be invoked directly via class name. In Java program “main()” method
is a static method which is called directly by JVM.
Example:
class PRG
{
public static void main(String args[ ])
{
//statements ;
}
}
11) Which methods can be overridden? Name the principle of OOP that
supports this feature.
ANS:
Instance methods can be overridden. Polymorphism supports this feature.

12) Write a program snippet to print “Hello World” on the screen. Which
type of method does it use?
ANS:
class Example
{
public static void main(String args [ ])
{
System.out.println(“Hello World”);
}
}
It uses static method.

13) Write program snippet to show the differences between static and
instance methods.
ANS:
Static Method:
class Example
{
public static void main(String args [ ])
{
System.out.println(“Hello World”);
}
}

Instance Method:
class PRG
{
void display() // instance method
{
//statements ;
}
public static void main(String args[ ])
{
PRG obj = new PRG() ;
obj.display();
}
}

14) A class is called an object factory. Explain with the help of an example.
ANS:
Each class describes possibly an infinite set of individual objects. So, it can be
called as a factory of objects. For example, a class of cellphone can have
numerous objects as Nokia, Samsung, Panasonic, etc. The features and functions
of the objects are described within the class.

class Example
{
void display()
{
System.out.println(“Hello World”);
}

public static void main(String args [ ])


{
Example OBJ = new Example();
OBJ.display();
}
}

Prepared by:
Mrs. Bhashwini Mittal

You might also like