Question

In: Computer Science

3. Given the test code below, what is the output to the console? public class TestMe{...

3. Given the test code below, what is the output to the console?

public class TestMe{

public TestMe(){

    System.out.print(“a”);

}

public void setUp(){

    System.out.print(“b”);

}

public void tearDown(){

    System.out.print(“c”);

}

@Test

public void testX(){

    System.out.print(“x”);

}

@Test

public void testY(){

    System.out.print(“y”);

}

}

A. abxcbyc

B. abxcabyc

C. bxcbyc

D. abxyc

Solutions

Expert Solution

Answer: abcxy

Explanation:

Program:

Explanation:

Line 1:// Here taking class name as TestMe
Line 2: //Creating constructor for TestMe class
Line 3: // Here Printing this statement
Line 4: // End of constructor
Line 5://Start of method setUp()
Line 6:// Here Printing this statement
Line 7:// End of method setUp()
Line 8://Start of method tearDown()
Line 9:// Here Printing this statement
Line 10: // End of method tearDown()
Line 11://Comments
Line 12://Start of method testX()
Line 13:// Here Printing this statement
Line 14: // End of method testX()
Line 15://Comments
Line 16://Start of method testY()
Line 17:// Here Printing this statement
Line 18: // End of method testY()
Line 19:// Start of main()
Line 20:// Here creating the object for class TestMe
Line 21:// calling the setUp() method using object ob
Line 22:// calling the tearDown() method using object ob
Line 23:// calling the testX() method using object ob
Line 24:// calling the testY() method using object ob
Line 25:// End of main()
Line 26:// End of TestMe class

Program:

public class TestMe{
public TestMe(){
System.out.print("a");
}
public void setUp(){
System.out.print("b");
}
public void tearDown(){
System.out.print("c");
}
//@Test
public void testX(){
System.out.print("x");
}
//@Test
public void testY(){
System.out.print("y");
}
public static void main(String args[]) {
TestMe ob=new TestMe();
ob.setUp();
ob.tearDown();
ob.testX();
ob.testY();
}
}
Output:


Related Solutions

GIVEN THE CODE BELOW Given the following class: /** * Document class. */ public class Document...
GIVEN THE CODE BELOW Given the following class: /** * Document class. */ public class Document { private int words; /** * constructor * pre: none * post: A Document object created. Words initialized to 0. */ public Document() { words = 0; //default words } /** * Changes the number of document words. * pre: none * post: Words has been changed. */ public void setWords(int numWords) { words = numWords; } /** * Calculates the number of pages....
Given the following code below: public class Calculation { //method that returns cube of the given...
Given the following code below: public class Calculation { //method that returns cube of the given number public int findMax(int arr[]){    int max=0;    for(int i=1;i<arr.length;i++){        if(max<arr[i]){           max=arr[i]; }     }     return max;   } //method that returns cube of the given number   public static int cube(int n){        return n*n*n;     }   } (5 points) Define the class CalculationTest a subclass of TestCase (10 points) Define a setUp() method (20 points) Define a test method testfindMax that exercises Calculation.findMax() in Calculation class (5 points)Define...
What output is produced by the following code?   Explain how it works. public class A {...
What output is produced by the following code?   Explain how it works. public class A { int a = 1; int b = 2; public int getSum(int a, int b) {     this.a+=a;     this.b+=b;     return this.a + this.b; } } public class B extends A { int a = 3; int b = 4; public int getSum(int a, int b) {     this.b=a;     super.b=b+b;     return super.a+this.b; } } public class q2 { public static void main(String[]...
1. Convert the following code shown below to C++ code: public class HighwayBillboard { public int...
1. Convert the following code shown below to C++ code: public class HighwayBillboard { public int maxRevenue(int[] billboard, int[] revenue, int distance, int milesRes) { int[] MR = new int[distance + 1]; //Next billboard which can be used will start from index 0 in billboard[] int nextBillBoard = 0; //example if milesRes = 5 miles then any 2 bill boards has to be more than //5 miles away so actually we can put at 6th mile so we can add...
Given the following code, what is output by the method call, mystery(6 * 8)? public static...
Given the following code, what is output by the method call, mystery(6 * 8)? public static void mystery (int x[]) {     System.out.println("A"); } public static void mystery (int x) {     System.out.println("B"); } public static void mystery (String x) {     System.out.println("C"); } A B C CA CB Which of the following is true about overloaded methods? Java cannot use a method's return type to tell two overloaded methods apart. Java cannot use a method's parameters to tell two overloaded methods apart....
Remove the Head element from the code below: public class LinkedList {    class Node{ int...
Remove the Head element from the code below: public class LinkedList {    class Node{ int value; Node nextElement; public Node(int value) { this.value = value; this.nextElement = null; } } public Node first = null; public Node last = null; public void addNewNode(int element) { Node newValueNode = new Node(element);    if(first == null) { first = newValueNode; } else { last.nextElement = newValueNode; } last = newValueNode; } public void displayValues() { Node recent = first; if(first ==...
For each call to the following method, indicate what console output is produced: public void mystery2(int...
For each call to the following method, indicate what console output is produced: public void mystery2(int n) { if (n <= 1) { System.out.print(n); } else { mystery2(n / 2); System.out.print(", " + n); } } mystery2(1); mystery2(4); mystery2(16); mystery2(30); mystery2(100);
(Be sure to paste the R Console Output and code!!!) Using the following data and R,...
(Be sure to paste the R Console Output and code!!!) Using the following data and R, write a brief paragraph about whether the in-home treatment is equally effective as the out-of-home treatment for two separate groups. Here are the data. The outcome variable is level of anxiety after treatment on a scale from 1 to 10. In-Home Treatment Out-of-Home Treatment 3 7 4 6 1 7 1 8 1 7 3 6 3 5 6 6 5 4 1 2...
A incomplete definition of a class Temperature is given below: public class Temperature { private double...
A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3}; } [6] (i) Copy and put it in a new class. Write a method toString() of the class, which does not have any parameters and returns a string containing all the values separated by newlines. When the string is printed, each value should appear on a line in the ascending order of their indexes. Copy the content of...
a. What will be the output of LINE A in code “a” and output of code...
a. What will be the output of LINE A in code “a” and output of code “b”? Also write reasons for the outputs. a. #include <sys/types.h> #include <stdio.h> #include <unistd.h> int value = 3; int main() { pid_t pid; pid = fork(); if (pid = = 0) {/* child process */} value += 233; return 0; } else if (pid > 0) {/* parent process */} wait(NULL); printf(“PARENT: value = %d”, value); /* LINE A */ return 0; } }...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT