WEEK-3
Q1. An object is an instance of a ________.
A) class
Q2. The keyword ________ is required to declare a class.
A) class
Q3. Analyze the following code:
class Circle {
private double radius;
public Circle(double radius) {
radius = radius;
}
}
A) The program will compile, but you cannot create an object of Circle with a specified radius. The object will always have radius 0.
Q4. ________ is invoked to create an object.
A) A constructor
Q5. Which of the following statements are true?
A)
1. A default constructor is provided automatically if no constructors are explicitly declared in the class.
2. The default constructor is a no-arg constructor.
Q6. Which of the following statements are true?
A)
1. Constructors are invoked using the new operator when an object is created.
2. Multiple constructors can be defined in a class.
3. Constructors must have the same name as the class itself.
4. Constructors do not have a return type, not even void.
Q7. What is the value of times displayed?
public class Test {
public static void main(String[] args) {
Count myCount = new Count();
int times = 0;
for (int i=0; i<100; i++)
increment(myCount, times);
System.out.println(
"myCount.count = " + myCount.count);
System.out.println("times = "+ times);
}
public static void increment(Count c, int times) {
c.count++;
times++;
}
}
class Count {
int count;
Count(int c) {
count = c;
}
Count() {
count = 1;
}
}
A) 0
Q8. Given the following code fragment
String strA = "aBcDeFg";
String strB = strA.toLowerCase;
strB = strB.toUpperCase;
String strC = strA.toUpperCase;
A) strB.compareTo(strC) would yield 0
Q9. What is the advantage of putting an image in a JLabel instance?
A) It becomes part of the component and is laid out automatically
Q10. These two ways of setting up a String yield identical results:
a) String string = new String("123.45");
b) String string = "" + 123.45;
A) TRUE
Comments
Post a Comment