WorksheetsQuiz 3
Total questions: 19
Worksheet time: 10mins
TJ04_01. What is the output of the following program? Be precise about where there are spaces and where there are newlines.
public class Ex4_1{
public static void zoop() {
baffle();
System.out.print("you foo ");
baffle(); }
public static void main(String[] args) {
System.out.print("No, I ");
zoop();
System.out.print("I ");
baffle(); }
public static void baffle() {
System.out.print("baz");
ping(); }
public static void ping() {
System.out.println("."); } }
the program doesn't stop
No, I baz.
you foo baz.
I baz.
none of the other choices is correct
you foo baz.
No, I baz.
I baz.
you foo baz.
No, I baz.
I baz.
TJ04_02. What is the output of the following program?
public class Ex4_2{
public static void zoop() {
baffle();
System.out.print("you foo ");
baffle(); }
public static void main(String[] args) {
System.out.print("No, I ");
zoop();
System.out.print("I ");
baffle(); }
public static void baffle() {
System.out.print("baz");
ping(); }
public static void ping() {
System.out.println(".");
baffle(); } }
you foo baz.
No, I baz.
I baz.
none of the other choices is correct
the program doesn't stop
No, I baz.
you foo baz.
I baz.
you foo baz.
No, I baz.
I baz.
TJ04_03. Choose what would be the correct first line of a method named zool that takes three parameters: an int and two Strings.
none of the other choices is correct
public void zool(int i, String s1, String s2)
public void zool(int i, String s1, s2)
public zool(int i , String ss, String ss)
public void zool(int, Str, Str)
TJ04_04. Identify the line of code that calls a method named zool, that takes three parameters: an int and two Strings, passing as arguments the value 11, the String "hello" and the String "world".
public void zool(11,"hello","world")
zool(11, hello, world)
zool(int, Str, Str)
none of the other choices is correct
zool(11,"hello", "world")
TJ04_06. Suppose you have a static method called printAmerican that takes the month (e.g. "July"), day (e.g. 23), year (e.g. 2018), and day of the week (e.g. "Thursday") as parameters and displays them in American format (e.g. Thursday, July 23, 2018). Which one of the following programs calls the method correctly to print the date.
public class PrintAmerican{
//method diefition goes here
public static void main(String[] aaa){
PrintAmerican("July", 23, 2018, "Thursday");
}
}
PrintAmerican.PrintAmerican("July", 23, 2018, "Thursday");
public class PrintAmerican{
//method definition goes here
public static void main(String[] aaa){
main.PrintAmerican("July", 23, 2018, "Thursday");
}
}
none of the other choices is correct
public class PrintAmerican{
//method definition goes here
public static void foo(String[] aaa){
PrintAmerican("July", 23, 2018, "Thursday");
}
}
TJ04_07. in the following code the print statements are numbered (the numbers look like //1, //2, //3, //4)
list the numbers in the order in which they are executed.
public class foo{
public static void main(String[] args) {
zippo("foo");
System.out.println("foo");//1
baffle("zoo");
}
public static void baffle(String blimp) {
System.out.println(blimp);//2
}
public static void zippo(String quince) {
System.out.println(quince);//3
System.out.println(quince);//4
}
}
3142
none of the other answers is correct
3412
1324
3124
TJ04_08. in order to use the Math class you must first import the package that contains it.
True
False
TJ04_09. One of the methods of the class Math is called atan.
True
False
TJ04_11. The largest possible long is 922,337,203,685
True
False
how much is 2 multiplied by itself 20 times?
2097152.0
1048576.0
4194304.0
524288.0
none of the other answers is correct
TJ04_13. each class can have only one method
True
False
TJ04_14. what is a reason to use methods
A common problem solving technique is to break tasks down into sub-problems.
all the answers shown here are reasons to use methods
Introducing new methods can make a program smaller by eliminating repetitive code
Creating a new method gives you an opportunity to give a name to a group of statements, which makes code easier to read and understand.
TJ04_16. what is printed by this program
class foo{
public static void zonk(String st1, String st2, String st3){
System.out.print(st3 + " " + st1 + " " + st2 + "\n");
}
public static void main(String[] args) {
zonk("this","method has","three arguments");
}
}
method has this three arguments
this method has three arguments
three arguments this method has
this three arguments method has
none of the other answers is correct
TJ04_17. the print statements of this program have been numbered (\\1,\\2,\\3,\\4). In what order are they executed
class foo{
public static void zonk1(String st){
System.out.print(st);//1
}
public static void zonk2(String st){
System.out.print(st);//2
}
public static void zonk3(String st){
System.out.print(st);//3
}
public static void main(String[] args) {
zonk2("foo");
zonk3("foo");
zonk1("foo");
System.out.println();//4
}
}
1234
2314
2134
2314
4132
TJ04_18. Suppose we have a method mm(int x).
that contains only the following statement:
x = 5;
what is printed if the main method has the following statements:
int x = 10;
mm(x);
System.out.println(x);
it is a compile time error
it is a runtime error
10
none of the other answers is correct
TJ04_19. Suppose we have a method mm(int y).
that contains only the following statement:
System.out.print(x);
what is printed if the main method only has the following statements:
int x = 10;
mm(x);
System.out.println(x);
10
1010
it is a compile time error
none of the other answers is correct
TJ04_21.
Suppose a class has the following method:
public static void printTime(int x) {
hour = 3*hour;
System.out.print(hour);
}
if the main method of the class contains the following code:
public static void main(String[] args) {
int hour = 1;
printTime(hour);
System.out.println(hour);
}
what would the main method print when it is executed.
31
11
none of the other answers is correct
it is a compile time error
TJ04_22. Javadoc
is another java compiler
it compiles java documents
none of the other answers is correct
it uses a different java virtual machine
is a document generator tool in Java programming language for generating standard documentation in HTML format
TJ04_24. Consider following code. In what order are the methods executed?
public class TJ04_24 {
public static void A(){
D();
G();
}
public static void B(){
}
public static void C(){
B();
F();
}
public static void D(){
}
public static void E(){
A();
C();
}
public static void F(){
D();
}
public static void G(){
B();
}
public static void main(String[] args) {
E();
}
}
mainEADGBCBFD
none of the other answers is correct
mainEAGDBCFBD
it doesn't end normally
ADGBCBFDEACFDGBmainE
