Advertisement
teaowl

Help 4 StackOverflow user

Jun 9th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. //Лаунчер, чтобы запускать
  2. public class ALauncher {
  3.  
  4.     public static void main(String[] args) {
  5.         B b = new B();
  6.         b.returnVariable();
  7.     }
  8.  
  9. }
  10. //ваш класс А
  11. class A {
  12.     int variable;
  13.     public A() {
  14.         setVariable(5);
  15.     }
  16.     public void setVariable(int variable) {
  17.         this.variable = variable;
  18.     }
  19.     public int getVariable() {
  20.         return variable;
  21.     }
  22. }
  23. //ваш класс В, с парой новых выводов
  24. class B {
  25.     void returnVariable() {
  26.         A a = new A();
  27.         System.out.println("A.variable is "+a.getVariable());
  28.         a.setVariable(6);
  29.         System.out.println("A.variable is "+a.getVariable());
  30.         a.setVariable(9);
  31.         System.out.println("A.variable is "+a.getVariable());
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement