+ 2

help java

public class Auto { // instance variables - replace the example below with your own String marka; boolean wypozyczone; /** * Constructor for objects of class Auto */ public Auto(String marka,boolean wypozyczone) { // initialise instance variables this.marka = marka; this.wypozyczone = wypozyczone; } public Auto(String marka) { // initialise instance variables this.marka = marka; } public static void main( String[] args ) { // put your code here Auto auto = new Auto("BMW", true); Auto auto1 = new Auto ("Hammer", false); Auto auto2 = new Auto("Mercedes"); Auto auto3 = new Auto("Opel"); System.out.println(auto + " 2: " + auto1 + " 3: " + auto2 + " 4: " + auto3); } } 1)Why the program shows me the next output: Auto@4909b8da 2: Auto@3a03464 3: Auto@2d3fcdbd 4: Auto@617c74e5 2) Why the second constructors also show the boolean result if I declare only a String?

1st Jan 2019, 7:24 PM
Kasia Herasymenko
Kasia Herasymenko - avatar
2 Answers
+ 4
1. "Auto@xxxx" is a reference, you are actually trying to print whole object. If you want make it work this way you can override toString() method in Auto class. 2. I don't really understand
1st Jan 2019, 7:30 PM
Michal
Michal - avatar
0
This code print the address (on memory) where your objects are stored.
1st Jan 2019, 7:34 PM
Théophile
Théophile - avatar