代表者の戯言

How to Send and Receive Data Across Classes in Java



Although this is a basic part of Java, let me introduce how to send and receive data across classes.


public class Datashow {

/////////////////////////////////////////////////

//This is "SHOW" side

/////////////////////////////////////////////////

String name;

int age;

Datashow(String a, int b) {

name = a;

age = b;

}

void dispMethod() {

System.out.println("name:" + name + " " + "age:" + age);

}

}

--------------------------------------------------------------------

public class Data {

/////////////////////////////////////////////////

//This is INPUT side

/////////////////////////////////////////////////

public static void main(String[] args) {

Datashow a1 = new Datashow("Mark", 19);

Datashow a2 = new Datashow("Jack", 25);

a1.dispMethod();

a2.dispMethod();

}

}