Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Objects

Multiple choice questions 10. Attributes that describe the object is:
(a) Information (b) method
1. Member variables are often called its _________, (c) data (d) name
and its member functions are referred to as its
11. Data attributes and behaviour methods
____________ in a class.
collectively is called
(a) attributes, methods (b) none of these
(a) Components (b) Associate
(c) values, morals (d) data, activities
(c) Part (d) Member
2. Keywords that are access specifiers
12. System which uses the concept of class that
(a) near and far (b) opened and closed
enables to express the set of objects that are
(c) table and row (d) private and public
abstractly equivalent differing only in the values
3. Use of __________ protects data from inadvertent
of their attributes?
modifications.
(a) Object oriented (b) Value oriented
(a) protect() member function
(c) Data oriented (d) All of these
(b) private access specifier
(c) class protection operator, @ 13. Element which can be considered as a blueprint
for various objects?
(d) none of these
4. Which other attribute can be use to distinguish, (a) Method (b) class
When two people have same name (c) object (d) member
(a) Colour (b) Name 14. What is a class for multiple objects with similar
(c) Birth date (d) Behavior features called?
5. How can we identify the value of attribute used ? (a) Image (b) representation
(a) Personality (b) Objects (c) template (d) guide
(c) Procedure (d) Identity 15. What things does a class describe with a group of
6. By whom the behavior is always associated? object and common behaviour?
(a) Personality (b) Objects (a) Features (b) attribute
(c) Procedure (d) Identity (c) values (d) States
7. Behavior of objects is called ? 16. Which element in the same class can share a
(a) Method (b) Technique common semantic purpose?
(c) Process (d) Procedure (a) Methods (b) classes
8. Property of object can be change due to its (c) objects (d) members
behavior ?
17. Name the concept which is used to embody all the
(a) State (b) Method
common features of a particular set of objects?
(c) Status (d) Class
(a) Method (b) class
9. To describe an object
(c) object (d) members
(a) What it is called (identity )
18. What represent a collection of classes ,constraints
(b) What it is (its state)
and relationship among classes?
(c) What it does (its behavior )
(a) Diagram (b) map
(d) All of these
(c) drawing (d) figure
19. How do we model the static view of an application? 30. Choose the correct address of memory location
(a) Diagram (b) map where only object is created for->
(c) drawing (d) figure Room r2= new RoomO :- variable R2
20. What do we call the variable which are of class (a) Memory (b) variable
type? (c) reference (d) none of these
(a) Orientation (b) position
Fill in the blanks
(c) reference (d) indication
21. Name the keyword that is used to create an object? 31. The class determines only the _________ of the
variables.
(a) Int (b) float
(a) types (b) collection
(c) new (d) real
(c) location (d) set
22. Identify that operator allocates the memory for
32. The actual __________ is contained inside the
an object and returns the address of the object for
individual objects and not in the class.
later use?
(a) information (b) data
(a) Int (b) Float
(c) collection (d) variables
(c) new (d) real
33. Every ________ has its own set of data.
23. The memory location where the object is stored is
(a) class (b) variable
known as?
(c) operator (d) object
(a) Memory (b) variable
34. ________ allocated different memory space to
(c) reference (d) none of these
hold their data values.
24. Name the special portion of memory where the (a) classes (b) variables
objects live?
(c) operators (d) objects
(a) heap (b) Pile
35. When ______ are no more needed the memory is
(c) stack (d) all of these claimed back to reuse.
25. When an object is created a special method is (a) classes (b) variables
executed to perform initial task what it is called? (c) operators (d) objects
(a) Function (b) constructor 36. In creating an object is also called ______
(c) class (d) method instantiation.
26. Which of the following is correct when an object (a) class (b) object
is created of type Room and assign its address to a (c) inheritance (d) polymorphism
variable r l 37. An ______ for an object is created by allocating
(a) rl=new room (); (b) rl=room () new; memory to store data for the object.
(c) RL= class room (); (d) None of these (a) instance (b) example
27. What is by default created, when there are empty (c) illustration (d) none of these
parentheses without arguments? 38. An object that belongs to a ________ is said to be
(a) Function (b) constructor an instance of that class
(c) class (d) method (a) cells (b) variables

28. What initialises the attributes (variables) of the (c) memory (d) class
object using default values? 39. And _______ of a class is another word for an
actual object.
(a) Function (b) constructor
(a) instance (b) example
(c) class (d) method
(c) memory (d) none of these
29. Which of the following contain arguments that
40. ______ is an abstract representation of an object
determine the initial values of variables?
where as an instance is its concrete representation
(a) Room (b) brackets
(a) cells (b) variables
(c) Parentheses (d) class
(c) memory (d) class
44. Match the columns:
Match the following
Group A Group B
41. Match the columns: 1. Declare class (i) class
variable
Group A Group B
2. Attributes and (ii) static
1. Instance and (i) methods
methods
Object
3. Passed by value (iii) methods
2. To define an (ii) OOP
4. Defined using (iv) parameters
object’s behavior
static keyword
3. Keyword for (iii) heap
(a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
object
4. Instance allocated (iv) new (b) 1-(i), 2-(ii), 3-(iv), 4-(iii)
in memory (c) 1-(ii), 2-(i), 3-(iii), 4-(iv)

(a) 1-(ii), 2-(i), 3-(iv), 4-(iii) (d) 1-(ii), 2-(iv), 3-(i), 4-(iii)
45. Match the columns:
(b) 1-(i), 2-(ii), 3-(iv), 4-(iii)
Group A Group B
(c) 1-(ii), 2-(i), 3-(iii), 4-(iv)
1. Called without (i) overloaded
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii) creating instance methods
42. Match the columns: 2. More than one (ii) class method
method having
Group A Group B
same name
1. Object Oriented (i) object
3. Invoked (iii) class
Programming
automatically
2. Unique entity (ii) data
4. methods are (iv) Constructor
3. Combining data (iii) inheritance
global
and methods
(a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
4. Class acquires (iv) encapsulation
properties from (b) 1-(i), 2-(ii), 3-(iv), 4-(iii)
another class (c) 1-(ii), 2-(i), 3-(iii), 4-(iv)
(d) 1-(ii), 2-(iv), 3-(ii), 4-(iii)
(a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
(b) 1-(i), 2-(ii), 3-(iv), 4-(iii) Programming based questions
(c) 1-(ii), 2-(i), 3-(iii), 4-(iv)
46. What is the use of constructor File Output Stream
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii)
(a) File not found exception
43. Match the columns: (b) File out of bounds exception
Group A Group B (c) File found exception
1. Blue print (i) instantiating a (d) None of these
class 47. Which instance will be created from the following
2. Creating objects of (ii) class FileOutputStreamfosobject= new File Output
a class Stream (“/home/Akash/myfile.txt”);
3. Restricting the free (iii) fundamental (a) File output stream (b) File input stream
flow of data concept OOPS
(c) File reader screen (d) File constructor
4. Object (iv) encapsulation
48. What is the subclass of input stream and is
(a) 1-(ii), 2-(i), 3-(iv), 4-(iii) generally used to read byte data from the file.
(b) 1-(i), 2-(ii), 3-(iv), 4-(iii) (a) File input stream
(c) 1-(ii), 2-(i), 3-(iii), 4-(iv) (b) File reader screen
(c) File writer screen
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii)
(d) File output stream
49. Name the method of file input stream class that Main obj = new Main();
reserve byte of data from this input stream.  ystem.out.println(“The name is “ + obj.
S
(a) Void close () (b) Int read (byte [] b) name);
(c) Int read() (c) Void write() }
50. Identify the method of file input stream class }
that closes the file input stream and releases any (a) W
 hat is the name of the constructor in the
system resources associated with the stream. above program
(a) Void close() (b) Int read (byte [] b) (i) Constructor
(c) Int read() (d) Void write() (ii) Main()
51. State the method of file input stream class that (iii) String[] args
reads up to b.length bytes of data from this (iv) Name
inputstream into an array of bytes
(b) What is variable in this program
(a) Void close() (b) Int read (byte [] b)
(i) Constructor
(c) Int read() (d) Void write()
(ii) Main()
52. Which of the following can get input from live
(iii) String[] args
interaction through keyboard/ GUI for it may
take input as command line arguments or from (iv) Name
the files. 57. Concerning the program code given below,
(a) Program (b) code answer the questions that follow:

(c) class (d) method class Helper

53. Which class belongs to the Java.util package? {

(a) Printer (b) console private int data;

(c) scanner (d) keyboard private Helper()

54. What is default delimiter? {

(a) Delimiter (b) printer data = 5;

(c) console (d) white space }

55. What can be of different type for example a string }


Like “India 1947” can also be read as a “string int” public class Test
values {
(a) Symbol (b) Token public static void main(String[] args)
(c) word (d) mark {
56. Concerning the program code given below, Helper help = new Helper();
answer the questions that follow: System.out.println(help.data);
class Main }
{ }
private String name; (a) What is the output of the following program?
// constructor (i) Compilation error
Main() (ii) 5
{ (iii) Runtime error
System.out.println(“Constructor Called:”); (iv) None of the above
name = “Programiz”; (b) W
 hat is the name of the constructor in the
} above program
public static void main(String[] args) (i) Constructor
{ (ii) Helper()
// constructor is invoked while (iii) String[] args
// creating an object of the Main class (iv) Name
58. Concerning the program code given below, public class Test
answer the questions that follow: {
classTemp public static void main(String[] args)
{ {
private Temp(intdata) Temp obj = Temp.create(20);
{ obj.myMethod();
System.out.print(“ Constructor called “); }
} }
protected static Temp create(int data) (a) What is the output of the following program?
{ (i) Constructor called method called
Temp obj = newTemp(data); (ii) Compilation error
returnobj; (iii) Runtime error
} (iv) None of the above
public void myMethod() (b) What is the name of the class object created?
{ (i) test
System.out.print(“ Method called “); (ii) obj
} (iii) String[] args
} (iv) Temp

Answers

Multiple choice questions Explanation: It is a basic unit of Object-Oriented


Programming and represents the real life entities.
1. (a) attributes, methods A typical Java program creates many objects,

Explanation: An attribute is another term for a which as you know, interact by invoking methods.
field. It’s typically a public constant or a public An object consists of : State: It is represented by
variable that can be accessed directly. attributes of an object.
A method is a block of code or collection of 6. (b) Objects
statements or a set of code grouped together to 7. (a) Method
perform a certain task or operation.
8. (a) State
2. (d) private and public
9. (d) All of these

Explanation: Private members cannot be accessed
10. (c) data
from the child class of the same package. Public
member can be accessed from non-child class 11. (d) Member
of same package. Private members cannot be Explanation: Member variables are known as
accessed from non-child class of same package. instance variables in java. Instance variables
Public members can be accessed from child class are declared in a class, but outside a method,
of outside package. constructor or any block. When space is allocated
3. (b) private access specifier for an object in the heap, a slot for each instance

Explanation: The private access modifier is variable value is created.
specified using the keyword private. The methods 12. (a) Object oriented
or data members declared as private are accessible Explanation: Java is an object-oriented
only within the class in which they are declared. programming language where every program has
private means “only visible within the enclosing at least one class. Programs are often built from
class”. many classes and objects, which are the instances
4. (c) Birth date of a class.
5. (b) Objects 13. (b) class
Explanation: A class is a group of objects which 40. (d) Class
have common properties. It is a template or
blueprint from which objects are created. Match the following
14. (c) template
41. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
15. (b) attribute
42. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
16. (c) objects
43. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
17. (b) class 44. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
18. (a) Diagram 45. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
19. (a) Diagram
20. (c) reference Programming based questions
21. (c) new
46. (a) File not found exception
22. (c) new
47. (a) File output stream
23. (c) reference
48. (d) File output stream
24. (a) heap
49. (c) Int read()
25. (b) constructor
50. (a) Void close()
Explanation: A constructor in Java is a special
51. (b) Int read (byte [] b)
method that is used to initialize objects. The
constructor is called when an object of a class is 52. (a) Program
created. 53. (d) keyboard
26. (a) rl=new room (); 54. (d) white space
27. (b) constructor 55.(b) Token
28. (b) constructor 56. (a) (ii) Main()
29. (c) Parentheses (b) (iv) Name
30. (c) reference 57. (a) (i) Compilation error
(b) (ii) Helper()
Fill in the blanks 58. (a) (i) Constructor called method called

31. (a) Types Explanation: When a constructor is marked as


private, the only way to create a new object of that
32. (b) Data
class from some external class is using a method
33. (d) Object that creates a new object, as defined above in the
34. (d) Objects program. The method creates () is responsible
35. (d) Objects for the creation of the Temp object from some
36. (b) Object other external class. Once the object is created, its
37. (a) Instance method can be invoked from the class in which
the object is created.
38. (d) Class
(b) (ii) obj
39. (a) Instance

You might also like