Ashok Garg, M-9312249405, Email: Ashok.ramniwas@gmail.
com, Skype Id:
1
ashokramniwas
Ch-3, Values and Data Types
A. Tick () the correct option.
1. Which among the following creates a blueprint to represent characteristic and behaviour of
an object?
a. Object b. Class c. Instance d. None of these
Ans.
2. Which among the following do not belong to an object?
a. State b. Behaviour c. Identity d. Class
Ans.
3. Which among the following is not a component of a class?
a. Modifiers b. Class name
c. Object d. Body
Ans.
4. Which among the following keyword is used to allocate memory space for an object?
a. new b. for c. while d. int
Ans.
5. Which among the following operator is used to access individual members of an object?
a. . (dot) b. + (plus) c. – (minus) d. / (divide)
Ans.
6. Which among the following modifier is used in a ‘class’?
a. public b. default c. Both a and b d. None of these
Ans.
7. Which among the following is a valid class name?
a. Simple Interest b. SimpleInterest c. 1SimpleInterest d. Simple@Interest
Ans.
8. Which among the following is a valid object name?
a. obj1 b. 1obj c. Obj 1 d. Obj#1
Ans.
9. Which among the following is used to represent behaviour in a class?
a. Method b. Data members c. Both a and b d. None of these
Ans.
10. If a method named show( ) is to be invoked using an object ‘ob’ , which among the following is
correct?
a. ob.show( ) b. ob.show c. show( ).ob d. None of these
Ans. a.
B. State whether the following statements are True (T) or False (F).
Ashok Garg, M-9312249405, Email: [email protected], Skype Id:
2
ashokramniwas
1. An object is called a class factory.
2. A class is an instance of an object.
3. A class is a mechanism to implement encapsulation.
4. Data members in a class is used to represent the characteristic of an object.
5. The new operator is used to create an object.
6. It’s a rule to have a class-name beginning in capital letter.
7. Java is case sensitive.
8. A class-name cannot be a keyword.
9. The dot operator is used to access members in an object using an object.
10. In programming every object will have a name.
C. Fill in the blanks.
1. A ------------------------- is a template that binds together data and methods together.
2. The values in the attributes of an object is called the ------------------- of an object.
3. The --------------- operator is used to access the individual members of a class.
4. The keyword ------------ is used to allocate memory space for an object.
5. The default and --------------- access modifier is used with a class.
6. It is a common convention to begin a class-name in ----------------- letter.
7. A class is called an --------------- factory.
8. ------------------- is used to give a unique name to an object for identification.
9. Behaviour of an object is represented by ------------------.
10. The size of fundamental data type is ------------------.
SECTION A
Answer the following questions.
1. State two differences between fundamental and user-defined data type.
Ans.
2. State two differences between a class and an object.
Ans.
3. Why is a class called a user-defined data type?
Ans.
4. What is an access specifier? Which two access specifier is used in a class declaration?
Ans.
5. Why is a class called an object factory?
Ans.
6. State two rules you should follow for naming a class.
Ashok Garg, M-9312249405, Email:
[email protected], Skype Id:
3
ashokramniwas
Ans.
7. What two conventions you should follow naming a class?
Ans.
8. State two conventions you should follow while naming a class.
Ans.
9. Write a statement in Java that will declare an object named si of the SimpleInterest class.
Ans
10. Rewrite the following program after removing the errors, underlining each corrections:
class My Class
{
int a, b;
void initialize( )
{
a=5;
b=6;
}
void show( )
{
System.out.println(a+ “ ”+ b);
}
static void main( )
{
My Class ob = new My Class( );
ob.initialize( );
show( ).ob;
}
}
Ans.
11. Which among the following are invalid class name in Java? State with reasons.
1. Compound Interest
Ans.
2. 1MyClass
Ans.
3. MyClass$
Ans.
Ashok Garg, M-9312249405, Email: [email protected], Skype Id:
4
ashokramniwas
4. Myclass#
Ans.
5. My@Class
Ans.