← Back to feed
Renewal·서른의 생활코딩

ex3) Java OOP

NS
normalstory
cover image


/*
class SampleClass { // class header section
    int a;
    int b; // member variable section
    int c;
 
    public SampleClass(int x, int y, int z) { // name is the same as the class name
    a = x;
    b = y;// constructor section.
    c = z;
    //x,y,z = SampleClass local variables
    }
 
    public int sum() { // method section
    int d;
    d = a + b + c;    //=d = this.a + this.b + this.c;
    return d;
    }
}

public class Class01 {
    public static void main(String[] args) {
    //SampleClass sam = new SampleClass();  // the values want exist because error

            // constructor " public SampleClass(int x, int y, int z) "is
            // if missing, default constructor creates and error is resolved.
    SampleClass sam = new SampleClass(1,2,3);
    System.out.print(sam.sum());
    }

}
**/

 

 

// if(same example variant) : method is static function's case

class SampleClass { // class header section
    static int a;
    static int b; // member variable section
    static int c;
 
    public SampleClass(int x, int y, int z) { // name is the same as the class name
    a = x;
    b = y; // constructor section.
    c = z;
              //x,y,z = SampleClass local variables
    }
 
    public static int sum() { // method section
    int d;
    d = a + b + c;    //=d = this.a + this.b + this.c;
    return d;
    }
}


public class Class01 {
    public static void main(String[] args) {
    //SampleClass sam = new SampleClass();  // the values want existbecause error
            // public SampleClass(int x, int y, int z)
            // if missing default constructor creates and error is resolved.
            // however all 0to initialized
    SampleClass sam = new SampleClass(1,2,3);
    System.out.print(sam.sum());
    }

}



// data structures! learn about


 

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.