1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ahat [919]
3 years ago
14

A. When executing System.out.println(a1), the toString() method in the Object class is invoked.

Computers and Technology
1 answer:
Zina [86]3 years ago
6 0

This question is incomplete, it lacks a piece of code to analyze.

I think you wanted an answer to the following question:

Analyze the following code:

public class Test {

   public static void main(String[] args) {

       Object a1 = new A();

       Object a2 = new Object();

       System.out.println(a1);

       System.out.println(a2);

   }

}

class A {

   int x;

   @Override

   public String toString() {

       return "A's x is " + x;

   }

}

A. When executing System.out.println(a1), the toString() method in the Object class is invoked.

B. When executing System.out.println(a2), the toString() method in the Object class is invoked

C. When executing System.out.println(a1), the toString() method in the A class is invoked.

D. The program cannot be compiled, because System.out.println(a1) is wrong and it should be replaced by System.out.println(a1.toString())

E. Both B and C.

Answer:

E. Both B and C.

Explanation:

<em>toString()</em> method is used to get the representation of this object as a string. When trying to display a string representation of an object usually the full name of the class will be displayed.

In the example above, line

<em>System.out.println(a2);</em>

would display something like

<em>[email protected]</em>

Obtained value can hardly serve as a good string description of an object. Therefore, <em>toString()</em> method is often overridden using <em>@Override</em> annotation (more info about <em>@Override</em> at https://beginnersbook.com/2014/07/override-annotation-in-java/)

Line  

<em>System.out.println(a1);</em>

would display <em>"A's x is 0" </em>because it uses <em>toString()</em> method overridden in class <em>A</em>.

You might be interested in
One of the most toxic components of a computer is the _________.a. plastic in the keyboardb. silicon in the glass of the compute
Burka [1]

Answer:

C. Lead embedded in the glass of the monitor.

Explanation:

Cathode Ray Tube (CRT) monitors have lead embedded in their glass. Exposure to small quantities of lead can lead to lead poisoning. There are about 2.2 kilograms of lead in a big CRT monitor.

This amount of lead is mixed with the glass to improve the optical quality and to stop radiation from affecting the user.

Exposure to lead can cause the following:

  1. Constipation.
  2. Irritability,
  3. Headaches
  4. Aggressive behavior and so much more.
3 0
3 years ago
Read 2 more answers
#include using namespace std; int main( ) { const int NUM_ROWS = 2; const int NUM_COLS = 2; int milesTracker[NUM_ROWS][NUM_COLS]
VARVARA [1.3K]

Answer:

#include <iostream>

using namespace std;

int main()

{

   const int NUM_ROWS = 2;

   const int NUM_COLS = 2;

   int milesTracker[NUM_ROWS][NUM_COLS];

   int i = 0;

   int j = 0;

   int maxMiles = -99; // Assign with first element in milesTracker before loop

   int minMiles = -99; // Assign with first element in milesTracker before loop

   milesTracker[0][0] = -10;

   milesTracker[0][1] = 20;

   milesTracker[1][0] = 30;

   milesTracker[1][1] = 40;

   

   maxMiles = milesTracker[0][0];

   minMiles = milesTracker[0][0];

   

   for (i = 0; i < NUM_ROWS; i++){

       for (j = 0; j < NUM_COLS; j++){

           if (milesTracker[i][j] > maxMiles){

               maxMiles = milesTracker[i][j];

           }

           if (milesTracker[i][j] < minMiles){

               minMiles = milesTracker[i][j];

           }

       }

   }

   

   cout << "Min: " << minMiles << endl;

   cout << "Max: " << maxMiles << endl;

   return 0;

}

Explanation:

It seems you want to find the min and max value in the array. Let me go through what I added to your code.

Set the maxMiles and minMiles as the first element in milesTracker

Create a nested for loop that iterates through the milesTracker. Inside the loop, check if an element is greater than maxMiles, set it as maxMiles. If an element is smaller than minMiles, set it as minMiles.

When the loop is done, print the minMiles and maxMiles

5 0
3 years ago
Write a statement that takes a variable named open_file that contains a file object and reads the next 12 characters into a vari
velikii [3]

Answer:

description=open_file.read(12)

Explanation:

A programming language in computer is a set formal languages that comprises a set of instruction which produce various kinds of output. It is used ti implement algorithms in computer programming.

In the context,  description=open_file.read(12) is the statement given to the computer as input which takes a variable named as open_file containing a file object and which reads the next 12 characters into the variable named as description.

6 0
3 years ago
Write a program in Java to input a letter. If it is an uppercase letter then
Vadim26 [7]

Answer:

The program is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 char chr;

 System.out.print("Input Character: ");

 chr = input.next().charAt(0);

 if(Character.isUpperCase(chr) == true){      chr+=5;  }

 else{      chr-=3;  }

 System.out.println("Encode Character: "+chr);

}

}

Explanation:

This declares the character

 char chr;

This prompts for input

 System.out.print("Input Character: ");

This gets the input from the user

 chr = input.next().charAt(0);

This checks for uppercase; if true, it is encoded by the next 5th

<em>  if(Character.isUpperCase(chr) == true){      chr+=5;  }</em>

If lowercase, it is encoded by the previous 3rd

 else{      chr-=3;  }

This prints the encoded character

 System.out.println("Encode Character: "+chr);

7 0
3 years ago
¿Que entiendes por computadora? <br><br><br> Me urgeee
cricket20 [7]
Que es lo que quieres decir mi amigo
5 0
3 years ago
Other questions:
  • Which are elements involved in diagramming a solution? Choose all that apply.
    10·1 answer
  • Your employer's right to electronically monitor you is an issue of ____.
    13·1 answer
  • Identify tags and attributes in HTML 5
    5·1 answer
  • What is the difference between "What I ought to do?" and "What kind of person should I be"?
    12·1 answer
  • To quit, a user types 'q'. To continue, a user types any other key. Which expression evaluates to true if a user should continue
    7·1 answer
  • which of these tools stick to the edge of an image, thus making it easy to select the shape of an image
    6·1 answer
  • HELLO <br> any edmentum people out there.
    15·2 answers
  • Learning is Fun
    5·1 answer
  • A(n) ___________ allows people at two or more locations to interact via two-way video and audio transmissions simultaneously as
    6·1 answer
  • The…..executed simple
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!