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

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 ==...
(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...
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);
Create a class called Height Copy the code for Height given below into the class. Remember...
Create a class called Height Copy the code for Height given below into the class. Remember – test the methods as you go Take a few minutes to understand what the class does. There are comments where you will have to be changing code. A list of changes are given Change the setFeet and setInches mutators to make sure the height and width will not be less than 0, no matter what is passed in to it Change constructor that...
public class Sum2 { // TODO - write your code below this comment. } Download the...
public class Sum2 { // TODO - write your code below this comment. } Download the Sum2.java file, and open it in jGrasp (or a text editor of your choice). This program takes two values as command-line arguments, converts them to ints via Integer.parseInt, and adds them together. Example output of this program is shown below, with the command-line arguments 3 4: Sum: 7
public class FirstChar { // TODO - write your code below this comment. } Download the...
public class FirstChar { // TODO - write your code below this comment. } Download the FirstChar.java file, and open it in jGrasp (or a text editor of your choice). This program takes a single command-line argument and prints out the first character of this argument, using String's charAt() method. If you're unsure how to pass command-line arguments to a program with jGrasp, see this tutorial. Example output of this program with the command-line argument foo is shown below: First...
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...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {    public static void main(String[] args)    {        for(int i = 1; i <= 4; i++)               //loop for i = 1 to 4 folds        {            String fold_string = paperFold(i);   //call paperFold to get the String for i folds            System.out.println("For " + i + " folds we get: " + fold_string);        }    }    public static String paperFold(int numOfFolds)  ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT