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
Which of the following class definitions is correct in Java?
(i)
Public class Employee
{
Private String name;
Private double salary;
Private int id; public Employee()
{
Name = "";
Salary = 0.0;
Id = 0;
} public Employee(String n, double s, int i)
{
Name = n;
Salary = s;
Id = i;
} public void print()
{
System.out.println(name + " " + id + " " + salary);
}
}
(ii)
Public class Employee
{
Private String name;
Private double salary;
Private int id; public void Employee()
{
Name = "";
Salary = 0.0;
Id = 0;
} public void Employee(String n, double s, int i)
{
Name = n;
Salary = s;
Id = i;
}
Public void print()
{
System.out.println(name + " " + id + " " + salary);
}
}
(Multiple Choice)
4.8/5
(33)
The abstract data type specifies the logical properties and the implementation details.
(True/False)
4.9/5
(42)
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 data member?
(Multiple Choice)
5.0/5
(31)
Members of a class are usually classified into three categories: public, private, and static.
(True/False)
4.8/5
(33)
Consider the following statements.public class Circle
{
Private double radius; public Circle()
{
Radius = 0.0;
} public Circle(double r)
{
Radius = r;
} public void set(double r)
{
Radius = r;
} public void print()
{
System.out.println(radius + " " + area + " "
+ circumference);
} public double area()
{
Return 3.14 * radius * radius;
} public double circumference()
{
Return 2 * 3.14 * radius;
}}Circle myCircle = new Circle();
Double r;Which of the following statements are valid in Java? (Assume that console is Scanner object initialized to the standard input device.)
(i)
R = console.nextDouble();
MyCircle.area = 3.14 * r * r;
System.out.println(myCircle.area);
(ii)
R = console.nextDouble();
MyCircle.set(r);
System.out.println(myCircle.area());
(Multiple Choice)
4.9/5
(38)
In ____ copying, each reference variable refers to its own object.
(Multiple Choice)
4.9/5
(27)
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.setX(10);
(True/False)
4.8/5
(38)
Suppose that Book is class with two instance variables-name of type String and numOfBooks of type int. Which of the following would be appropriate syntax for the heading of a copy constructor for the class called Book?
(Multiple Choice)
4.8/5
(42)
If the object is created in the definition of a method of the class, then the object can access both the public and private members of the class.
(True/False)
4.9/5
(43)
Showing 41 - 50 of 50
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)