Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. // Create a MyClass class
  2. public class MyClass {
  3.   int x;  // Create a class attribute
  4.  
  5.   // Create a class constructor for the MyClass class
  6.  // public MyClass(int y) {
  7.    // x = y;  // Set the initial value for the class attribute x
  8.   //}
  9.  
  10.   public void info(int y) {
  11.     x = y;  // Set the initial value for the class attribute x
  12.     //return x;
  13.   }
  14.  
  15.   public int result() {
  16.       return x;
  17.   }
  18.  
  19.   public static void main(String[] args) {
  20.  
  21.     MyClass obj[] = new MyClass[2];
  22.     obj[0] = new MyClass();
  23.     obj[1] = new MyClass();
  24.     obj[0].info(5);
  25.     obj[1].info(6);
  26.     for (int i = 0; i < obj.length; i++) {
  27.  
  28.  
  29.             int z = obj[i].result();
  30.             System.out.print(z + "\n");
  31.         }
  32.     //System.out.println("ab..");
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement