0
How to display a variable belonging to a class in a constructor.
Here is the code; private class House { Public String color; House (){ color="red"; } } public static void main (String []args){ House r= new House (); /**when I run this code, there is no output. How do I display "red" from this code. At first I wrote " House.r ();" but it still shows no output. If someone could explain and give me the solution. I'll appreciate it. */
2 Respuestas
0
I think you have to use the get command
public static void main(String[ ] args) {
Vehicle v1 = new Vehicle();
v1.setColor("Red");
System.out.println(v1.getColor());
}
//Outputs "Red"
0
Thank you but the code you giving me is referring to a constructor that takes parameters. I am looking to display a code a constructor without a parameter whereby the color is red. I appreciate the reply though.