Exam 8: User-Defined Classes
Exam 1: An Overview of Computers and Programming Languages50 Questions
Exam 2: Basic Elements of Java50 Questions
Exam 3: Introduction to Objects and Input/output50 Questions
Exam 4: Control Structures I: Selection50 Questions
Exam 5: Control Structures II: Repetition50 Questions
Exam 6: Graphical User Interface GUI and Object-Oriented Design OOD50 Questions
Exam 7: User-Defined Methods50 Questions
Exam 8: User-Defined Classes50 Questions
Exam 9: Arrays46 Questions
Exam 10: Inheritance and Polymorphism50 Questions
Exam 11: Handling Exceptions and Events50 Questions
Exam 12: Advanced Guis and Graphics48 Questions
Exam 13: Recursion50 Questions
Exam 14: Applications of Arrays Searching and Sorting and Strings50 Questions
Select questions type
A mutator method of a class changes the values of the data members of the class.
(True/False)
4.8/5
(44)
public class Secret
{
Private int x;
Private static int y;
Public static int count;
Public int z;
Public Secret()
{
X = 0;
Z = 1;
} public Secret(int a)
{
X = a;
} public Secret(int a, int b)
{
X = a;
Y = b;
} public String toString()
{
Return ("x = " + x + ", y = " + y + ",
Count = " + count);
} public static void incrementY()
{
Y++;
}
}What might the heading of the copy constructor for the class in the accompanying figure look like?
(Multiple Choice)
5.0/5
(30)
In shallow copying, each reference variable refers to its own object.
(True/False)
4.8/5
(30)
Consider the following class definition.public class Rectangle
{
Private double length;
Private double width; public Rectangle()
{
Length = 0;
Width = 0;
} public Rectangle(double l, double w)
{
Length = l;
Width = w;
} public void set(double l, double w)
{
Length = l;
Width = w;
} public void print()
{
System.out.println(length + " " + width);
} public double area()
{
Return length * width;
} public double perimeter()
{
Return 2 * length + 2 * width;
}
}Which of the following statements correctly instantiates the Rectangle object myRectangle?
(i) myRectangle = new Rectangle(12.5, 6);
(ii) Rectangle myRectangle = new Rectangle(12.5, 6);
(iii) class Rectangle myRectangle = new Rectangle(12.5, 6);
(Multiple Choice)
4.8/5
(46)
Consider the following class definition.public class Cylinder
{
Private double baseRadius;
Private double height; public Cylinder ()
{
BaseRadius = 0;
Height = 0;
} public Cylinder (double l, double h)
{
BaseRadius = l;
Height = h;
} public void set(double r, double h)
{
BaseRadius = r;
Height = h;
} public String toString()
{
Return (baseRadius + " " + height);
} public double SurfaceArea()
{
Return 2 * 3.14 * baseRadius * height;
} public double volume()
{
Return 3.14 * baseRadius * baseRadius * height;
}
}Suppose that you have the following declaration. Cylinder cyl = new Cylinder(1.5, 10);Which of the following sets of statements are valid in Java?
(i)
Cyl.surfaceArea();
Cyl.volume();
Cyl.print();
(ii)
Print(cyl.surfaceArea);
Print(cyl.volume());
(Multiple Choice)
4.9/5
(44)
MysteryClass
-first: int
-second: double;
+MysteryClass()
+MysteryClass(int)
+MysteryClass(double);
+MysteryClass(int, double)
+setData(int, double): void
+getFirst(): int
+getSecond(): double
+doubleFirst(): int
+squareSecond(): double
+print(): void
+equals(MysteryClass): boolean
+makeCopy(MysteryClass): void
+getCopy():MysteryClass
According to the UML class diagram in the accompanying figure, which method is public and doesn't return anything?
(Multiple Choice)
4.9/5
(44)
public class Secret
{
Private int x;
Private static int y;
Public static int count;
Public int z;
Public Secret()
{
X = 0;
Z = 1;
} public Secret(int a)
{
X = a;
} public Secret(int a, int b)
{
X = a;
Y = b;
} public String toString()
{
Return ("x = " + x + ", y = " + y + ",
Count = " + count);
} public static void incrementY()
{
Y++;
}
}Based on the class in the accompanying figure, which of the following statements is illegal?
(Multiple Choice)
4.9/5
(44)
The method finalize automatically executes when the class object goes out of scope.
(True/False)
4.8/5
(39)
In Java, the reference this is used to refer to only the methods, not the instance variables of a class.
(True/False)
4.8/5
(38)
The built-in operation that is valid for classes is the dot operator.
(True/False)
4.8/5
(48)
An accessor method of a class first accesses the values of the data members of the class and then changes the values of the data members.
(True/False)
4.8/5
(32)
public class Secret
{
Private int x;
Private static int y;
Public static int count;
Public int z;
Public Secret()
{
X = 0;
Z = 1;
} public Secret(int a)
{
X = a;
} public Secret(int a, int b)
{
X = a;
Y = b;
} public String toString()
{
Return ("x = " + x + ", y = " + y + ",
Count = " + count);
} public static void incrementY()
{
Y++;
}
}What does the default constructor do in the class definition in the accompanying figure?
(Multiple Choice)
4.9/5
(32)
In deep copying, each reference variable refers to its own object.
(True/False)
4.8/5
(44)
When no object of the class type is instantiated, static data members of the class fail to exist.
(True/False)
4.9/5
(39)
Showing 21 - 40 of 50
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)