Class-and-object
Question 1 |
What is the output of the following JAVA program ?
Class Test {
public static void main(String[] args) {
Test obj = new Test();
obj.start();
}
void start() {
String stra = ”do”;
String strb = method(stra);
System.out.print(“: ”+stra + strb);
}
String method(String stra) {
stra = stra + ”good”;
System.out.print(stra);
return“ good”;
}
}
Class Test {
public static void main(String[] args) {
Test obj = new Test();
obj.start();
}
void start() {
String stra = ”do”;
String strb = method(stra);
System.out.print(“: ”+stra + strb);
}
String method(String stra) {
stra = stra + ”good”;
System.out.print(stra);
return“ good”;
}
}
dogood : dogoodgood | |
dogood : gooddogood | |
dogood : dodogood | |
dogood : dogood |
Question 2 |
The memory occupied by an object type of data in VB is
1 byte | |
2 byte | |
4 byte | |
8 byte |
Question 2 Explanation:
Question 3 |
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
Protected and public data only in C and B | |
Protected and public data only in C | |
Private data in A and B | |
Protected data in A and B |
Question 3 Explanation:
The following table shows the access to members permitted by each modifier.
Question 4 |
Members of class by default are
Public | |
Private | |
Protected | |
Mandatory to specify |
Question 4 Explanation:
→A class in C++ is a user defined type or data structure declared with keyword class that has data and functions (also called methods) as its members whose access is governed by the three access specifiers private, protected or public (by default access to members of a class is private).
→The private members are not accessible outside the class; they can be accessed only through methods of the class. The public members form an interface to the class and are accessible outside the class.
→The private members are not accessible outside the class; they can be accessed only through methods of the class. The public members form an interface to the class and are accessible outside the class.