0

Java Classes

Example. I have 4 classes . 1 main 2 red 3 blue 4 black. How to in class 3 and 4 set Integer value with void method in class 2 and value import in class 1

20th Jun 2017, 9:56 PM
Amy Brown
Amy Brown - avatar
2 Respuestas
0
Firstly, classes are written with capital letter, otherwise, I might mistake them with objects or variables. This can also be done without class instances, meaning using statc variables and methods. publc class Black { static int value=10; } public class Blue { public static void setRedValue(){ Red.value = Black.value; } } public class Red { public static value int=0; } public Main { public static void main (String [] args){ Blue.setRedValue(); System.out.println (Red.value)); // =10 } }
21st Jun 2017, 4:09 AM
Claudiu Stefan Haidu
Claudiu Stefan Haidu - avatar
0
How with setters and getters if value is private
21st Jun 2017, 4:27 PM
Amy Brown
Amy Brown - avatar