Exam 10: Thinking in Objects
Exam 1: Introduction to Computers, Programs, and Java9 Questions
Exam 2: Elementary Programming16 Questions
Exam 3: Selections21 Questions
Exam 4: Loops12 Questions
Exam 5: Methods17 Questions
Exam 6: Single-Dimensional Arrays8 Questions
Exam 7: Multidimensional Arrays8 Questions
Exam 8: Objects and Classes15 Questions
Exam 9: Strings24 Questions
Exam 10: Thinking in Objects25 Questions
Select questions type
What is the printout for the following code? class Test {
Public static void main(String[] args) {
Int[] x = new int[3];
System.out.println("x[0] is "+x[0]);
}
}
Free
(Multiple Choice)
4.9/5
(38)
Correct Answer:
C
Suppose s is a string with the value "java". What will be assigned to x if you execute the following code? char x = s.charAt(4);
Free
(Multiple Choice)
4.8/5
(45)
Correct Answer:
C
To append data to an existing file, use _____________ to construct a FileOutputStream for file out.dat.
Free
(Multiple Choice)
4.8/5
(39)
Correct Answer:
C
Suppose the xMethod() is invoked in the following constructor in a class, xMethod() is _________ in the class. public MyClass() {
XMethod();
}
(Multiple Choice)
4.8/5
(25)
Analyze the following code: public class Test {
Private int t;
Public static void main(String[] args) {
Test test = new Test();
System.out.println(test.t);
}
}
(Multiple Choice)
4.9/5
(34)
What is the output of running class C?
class A {
public A() {
System.out.println(
"The default constructor of A is invoked");
}
}
class B extends A {
public B() {
System.out.println(
"The default constructor of B is invoked");
}
}
public class C {
public static void main(String[] args) {
B b = new B();
}
}
a. none
b. "The default constructor of B is invoked"
c. "The default constructor of A is invoked" followed by "The default constructor of B is invoked"
d. "The default constructor of A is invoked"
(Essay)
4.9/5
(30)
Which code fragment would correctly identify the number of arguments passed via the command line to a Java application, excluding the name of the class that is being invoked?
(Multiple Choice)
4.8/5
(35)
What modifier should you use on a variable so that it can only be referenced inside its defining class.
(Multiple Choice)
4.9/5
(45)
What would be the result of attempting to compile and run the following code? public class Test {
Static int x;
Public static void main(String[] args){
System.out.println("Value is " + x);
}
}
(Multiple Choice)
4.7/5
(42)
When you implement a method that is defined in a superclass, you __________ the original method.
(Multiple Choice)
4.7/5
(38)
Text I/O
Write a program that will count the number of characters (excluding control characters '\r' and '\n'), words, and lines, in a file. Words are separated by spaces, tabs, carriage return, or line-feed characters. The file name should be passed as a command-line argument, as shown in the following sample run. 

(Essay)
4.9/5
(34)
Suppose the xMethod() is invoked from a main method in a class as follows, xMethod() is _________ in the class. public static void main(String[] args) {
XMethod();
}
(Multiple Choice)
4.7/5
(33)
Show the output of running the class Test in the following code lines: interface A {
Void print();
}
Class C {}
Class B extends C implements A {
Public void print() { }
}
Class Test {
Public static void main(String[] args) {
B b = new B();
If (b instanceof A)
System.out.println("b is an instance of A");
If (b instanceof C)
System.out.println("b is an instance of C");
}
}
(Multiple Choice)
4.7/5
(37)
Design and use interfaces
Write a class named Octagon that extends GeometricObject and implements the Comparable and Cloneable interfaces. Assume that all eight sides of the octagon are of equal size. The area can be computed using the following formula:
Draw the UML diagram that involves Octagon, GeometricObject, Comparable, and Cloneable.

(Short Answer)
4.8/5
(31)
After the following program is finished, how many bytes are written to the file t.dat? import java.io.*;
Public class Test {
Public static void main(String[] args) throws IOException {
DataOutputStream output = new DataOutputStream(
New FileOutputStream("t.dat"));
Output.writeShort(1234);
Output.writeShort(5678);
Output.close();
}
}
(Multiple Choice)
4.7/5
(49)
Design and create GUI applications
Write a Java applet to add two numbers from text fields, and displays the result in a non-editable text field. Enable your applet to run standalone with a main method. A sample run of the applet is shown in the following figure. 

(Essay)
4.8/5
(37)
If a class named Student has no constructors defined explicitly, the following constructor is implicitly provided.
(Multiple Choice)
4.8/5
(34)
How can you get the word "abc" in the main method from the following call? java Test "+" 3 "abc" 2
(Multiple Choice)
4.8/5
(35)
If a class named Student has a constructor Student(String name) defined explicitly, the following constructor is implicitly provided.
(Multiple Choice)
4.9/5
(43)
Showing 1 - 20 of 25
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)