I have the following class:
public class Example {
private String name;
private int year;
public Example() {
name = "Clifford the big red dog";
year = 2020;
}
public void showData() {
// ?????
}
}
Imagine in the main class I create an object of the previous class (Example
) and execute it's constructor. Then I want to execute showData()
and I would like to see the following output (given this example):
String name Clifford the big red dog
int year 2020
The main would look like this:
public static void main () {
Example example = new Example();
example.showData();
}
Is there any way I can do this?