IU Bloomington Evaluation Services and Testing

Indiana University
Bloomington Evaluation Services and Testing

QuizSite  Students
Quizzes · Tests · Evaluations · Surveys
Activity: Practice_Four
Student: dgerman (Adrian German)
Instructor: dgerman
Course: J201 Section: 4285
Question 1.
You compile and run this program. What is the output that it produces?
class One {
  int a = 0;
  int b = 0;
  void fun() {
    b += 1;
    a += 1;
    System.out.print(a + " " + b + " ");
  }
  public static void main(String[] args) {
    One alpha = new One();
    alpha.fun();
    alpha.fun();
    alpha.fun();
  }
}

1 1 2 2 3 3
1 1 2 1 3 1
1 0 2 0 3 0
1 1 1 2 1 3


Question 2.
You compile and run this program. What is the output that it produces?
class One {
  int a = 0;
  int b = 0;
  void fun() {
    b += 1;
    a += 1;
    System.out.print(a + " " + b + " ");
  }
  public static void main(String[] args) {
    One alpha = new One();
    One beta = new One();
    alpha.fun();
    beta.fun();
    alpha.fun();
  }
}

1 1 2 2 3 3
1 1 2 1 3 1
1 1 1 1 2 2
1 1 1 2 1 3


Question 3.
You compile and run this program. What is the output that it produces?
class One {
  int a = 0;
  static int b = 0;
  void fun() {
    b += 1;
    a += 1;
    System.out.print(a + " " + b + " ");
  }
  public static void main(String[] args) {
    One alpha = new One();
    One beta = new One();
    alpha.fun();
    beta.fun();
    alpha.fun();
  }
}

1 1 2 1 3 1
1 1 2 1 3 2
1 1 1 2 1 3
1 1 1 2 2 3


Question 4.
What is the result of attempting to compile and run the following code?
class One {
  int value;
  One () {
    value = 3;
  }
  public static void main(String[] args) {
    One alpha = new One(3);
    One beta = new One();
    System.out.println(alpha.value + " " + beta.value);
  }
}

The program does not compile.
The program compiles and runs and outputs 0 0
The program compiles and runs and outputs 3 0
The program compiles and runs and outputs 0 3
The program compiles and runs and outputs 3 3


Question 5.
What is the result of attempting to compile and run the following code?
class One {
  int value;
  One (int v) {
    value = 0;
  }
  One () {
    value = 3;
  }
  public static void main(String[] args) {
    One alpha = new One();
    One beta = new One(3);
    System.out.println(alpha.value + " " + beta.value);
  }
}

The program does not compile.
The program compiles and runs and outputs 0 0
The program compiles and runs and outputs 3 0
The program compiles and runs and outputs 0 3
The program compiles and runs and outputs 3 3


Question 6.
What is the result of attempting to compile and run the following code?
class One {
  static int value;
  One (int v) {
    value = v;
  }
  public static void main(String[] args) {
    One alpha = new One(0);
    One beta = new One(3);
    System.out.println(alpha.value + " " + beta.value);
  }
}

The program does not compile.
The program compiles and runs and outputs 0 0
The program compiles and runs and outputs 3 0
The program compiles and runs and outputs 0 3
The program compiles and runs and outputs 3 3


Question 7.
What is the result of attempting to compile and run the following code?
class One {
  static int value;
  public static void main(String[] args) {
    One alpha = new One();
    One beta = new One();
    System.out.println(alpha.value + " " + beta.value);
  }
}

The program does not compile.
The program compiles and runs and outputs 0 0
The program compiles and runs and outputs 3 0
The program compiles and runs and outputs 0 3
The program compiles and runs and outputs 3 3


Question 8.
Consider the following class defintion below? How many instance members does it define for objects of class One?
class One {
  public static void main(String[] args) {
    int a = 0, b = 1;
    System.out.println(" a + b = " + (a + b));
  }
}

One cannot create objects of this class, because there is no constructor defined.
No instance members, the objects will be empty.
One instance member.
Two variables and a method.


Question 9.
Consider the following Java code
class Beta {
}
class Gamma {
  public static void main(String[] args) {
    System.out.println("Hello");
  }
}
that you place in a file Alpha.java and compile.

What .class files get created?


Alpha.class only
Alpha.class and Gamma.class only
Beta.class and Gamma.class only
Alpha.class, Beta.class and Gamma.class


Question 10.
What is the output produced by the following code when embedded in a complete program?
int myInt = 3;
if (myInt < 5)
  if (myInt < 3)
    System.out.println("less than 3");
else
  if (myInt > 2)
    System.out.println("greater than 2");
else
  System.out.println("other");

"less than 3"
"greater than 2"
"other"
nothing


Click to submit your answers.   Help


This activity is available between these dates and times: 07.08.10:00-08.11.19:59
It can be submitted a total of 30 times.
If it is a scored activity, the highest non-zero score will be counted.


Screen: TAKE_QUIZ
Last updated: Thu Mar 8 13:40:07 2001
URL: https://www.indiana.edu/~best/cgi-bin/quizsite/students.pl
Comments: best@indiana.edu
Copyright 2000, BEST & The Trustees of Indiana University