09-17-2013

posted Sep 17, 2013, 8:38 PM by Samuel Konstantinovich   [ updated Sep 17, 2013, 8:38 PM ]
Java code for reference:

EXAMPLE 1:
file: helloworld.java
public class helloworld{
    public static void main(String[]args){
        System.out.println("Hello world");
    }
}

EXAMPLE 2 (2 files)
file: Demo.java
public class Demo{
    public static void main(String[]args){
        something X,bob;
    
        //create 2 instances of the something class (instantiate)
        X=new something();
        bob=new something();

        //manually set the variables inside of the X object:
        X.a=3;
        X.b=-2;

        //call the method 'print' from in the something class
        X.print();
        bob.print();
    
    }
}

file: something.java
public class something{
    int a,b;
    public something(){
    }

    public void print(){
        System.out.println(a+","+b);
    }
}

Comments