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
Not every user-defined class can override the default definition of the method toString because it is provided by Java.
Free
(True/False)
4.8/5
(35)
Correct Answer:
False
Consider the following statements.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 = " + length
+ "; Width = " + width + "\n" +
+ " Area = " + area()
+ "; Perimeter = " + perimeter());
} public double area()
{
Return length * width;
} public void perimeter()
{
Return 2 * length + 2 * width;
} public void makeCopy(Rectangle otherRect)
{
Length = otherRect.length;
Width = otherRect.width
}
}Rectangle tempRect = new Rectangle(14, 10);
Rectangle newRect = new Rectangle(9, 5);What are the values of the instance variables of newRect after the following statement execute?newRect.makeCopy(tempRect);
Free
(Multiple Choice)
4.8/5
(40)
Correct Answer:
A
Which of the following is used to allocate memory for the instance variables of an object of a class?
Free
(Multiple Choice)
4.7/5
(38)
Correct Answer:
C
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
Which of the following would be a default constructor for the class MysteryClass shown in the accompanying figure?
(Multiple Choice)
4.7/5
(26)
Which of the following words indicates an object's reference to itself?
(Multiple Choice)
4.7/5
(45)
Classes that are defined within other classes are called inside classes.
(True/False)
4.9/5
(32)
Given the declaration public class MyClass
{
private int x; public void print()
{
System.out.println("x = " + x);
} private void setX(int y)
{
x = y;
}
}
MyClass myObject = new MyClass();The following statement is legal.myObject.print();
(True/False)
4.8/5
(31)
If a member of a class is a private method, you can access it outside the class.
(True/False)
4.8/5
(40)
Which of the following is a constructor without parameters?
(Multiple Choice)
4.9/5
(40)
The default constructor executes when an object is instantiated and initialized using an existing object.
(True/False)
4.8/5
(34)
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 of the following is a private member of the class MysteryClass?
(Multiple Choice)
4.8/5
(32)
A class and its members can be described graphically using Unified Modeling Language (UML) notation.
(True/False)
4.7/5
(41)
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++;
}
}How many constructors are present in the class definition in the accompanying figure?
(Multiple Choice)
4.7/5
(29)
Showing 1 - 20 of 50
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)