Class-and-object

Question 1
Which of the following is associated with objects?
A
State
B
Behaviour
C
Identity
D
All of the above
Question 1 Explanation: 
→ An object can be a variable, a data structure, a function, or a method, and as such, is a value in memory referenced by an identifier.
→ In the class based object-oriented programming paradigm, object refers to a particular instance of a class, where the object can be a combination of variables, functions, and data structures.
→ An object has state, exhibits some well defined behavior, and has a unique identity.
Question 2
If a class C is derived from class B, which is derived from class A, all through public inheritance, then a class C member function can access
A
only protected and public data of C and B
B
Only protected and public data of C
C
all data of C and private data of A and B
D
public and protected data of A and B and all data of C
Question 2 Explanation: 
→ It is nothing but multilevel inheritance.
→ If a class C is derived from class B, which is derived from class A, all through public inheritance, then a class C member function can access public and protected data of A and B and all data of C
Question 3
What is the right way to declare a copy constructor of a class if the name of the class is MyClass?
A
MyClass (constant MyClass *arg)
B
MyClass (constant MyClass &arg)
C
MyClass (MyClass arg)
D
MyClass (MyClass *arg)
Question 3 Explanation: 
→Copy Constructor is a type of constructor which is used to create a copy of an already existing object of a class type.
→Declaration of copy constructor syntax is different from c++ to java.
→In C++, It is usually of the form class-name (Class_name &vn),
→In Java, the syntax is Class_name(class_name vn).
→So w.r.to C++ , option (B) is correct and w.r.to Java option (c ) is correct.
Question 4
If only one memory location is to be reserved for a class variable, no matter how many objects are instantiated, then the variable should be declared as
A
extern
B
static
C
volatile
D
const
Question 4 Explanation: 
→ The static storage class instructs the compiler to keep a local variable in existence during the life-time of the program instead of creating and destroying it each time it comes into and goes out of scope. Therefore, making local variables static allows them to maintain their values between function calls.
→ The static modifier may also be applied to global variables. When this is done, it causes that variable's scope to be restricted to the file in which it is declared.
→ In C programming, when static is used on a global variable, it causes only one copy of that member to be shared by all the objects of its class.
Question 5
Which of the following is/are true about packages in Java?
1) Every class is part of some package
2) All classes in a file are part of the same package
3)If no package is specified, the classes in the file go into a special unnamed package.
4) If no package is specified, a new package is created with folder name of class and the class is put in this package
A
Only 1,2 and 3
B
Only 1,2 and 4
C
Only 4
D
Only 1 and 3
Question 5 Explanation: 
Option -4 false because new package is created by using syntax package package_name which is user defined .There is no relation with class name.
There are 5 questions to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access