Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create a MyClass class
- public class MyClass {
- int x; // Create a class attribute
- // Create a class constructor for the MyClass class
- // public MyClass(int y) {
- // x = y; // Set the initial value for the class attribute x
- //}
- public void info(int y) {
- x = y; // Set the initial value for the class attribute x
- //return x;
- }
- public int result() {
- return x;
- }
- public static void main(String[] args) {
- MyClass obj[] = new MyClass[2];
- obj[0] = new MyClass();
- obj[1] = new MyClass();
- obj[0].info(5);
- obj[1].info(6);
- for (int i = 0; i < obj.length; i++) {
- int z = obj[i].result();
- System.out.print(z + "\n");
- }
- //System.out.println("ab..");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement