5 (kkman@mail.sangji.ac.kr)
(Class), (template) (Object)
public, final, abstract [modifier] class ClassName { // // (, )
Class Circle { int radius, color ; int x, y ; float getarea() { return 3.14159 * radius * radius ; Class Rectangle { int width, height ; int x, y ; int getarea() { return width * height ;
public class Fraction { // int numerator; // int denominator; // public Fraction add(fraction f) /*... */ public Fraction mul(fraction f) /*... */ public void printfraction() /*... */ public public public
(reference) (constructor) :
:. :. f1.numerator f1.add(f2) 5.1
public, protected, private private package protected public O O O O X X O O X O O O X X X O
private int i; int j; protected int k; public int sum; // private // package // protected // public private class PrivateClass { private int iamprivate; // class AnotherClass { void accessmethod() PrivateAccess pa = new PrivateAccess(); pa.iamprivate = 10; //
public class PublicAccess { public int iampublic; // class AnotherClass { void accessmethod() PublicAccess pa = new PublicAccess(); pa.iampublic = 10; // OK package protected
(qualifier) [1/2] static class StaticVariable { public static int numofitems = 0; public int value; // StaticVariable p = new StaticVariable(); StaticVariable.numOfItems ( )
(qualifier) [2/2] final static+final : class QualifierExample { int aninteger; static int staticinteger = 0; static final double = 3.14159265358979323846; volatile
, static, final, native, synchronized class MethodExample { int simplemethod() { //... public void emptymethod() {
public String tostring() { String form = numerator + "/" + denominator; return form; (external representation) ++=, tostring string value = " + obj [ 5.2]
tostring() class Fraction { int numerator, denominator; public String tostring() { String form = numerator + / + denominator; return form; // public class ExampleOftoString { public static void main(string[] args) { Fraction f = new Fraction(1, 2); System.out.println( Implicit call = + f); System.out.println( Explicit call = + f.tostring());
(global function) ClassName.methodName;
(final method) synchronized
(formal parameter) (actual parameter) void parameterpass(int i, Fraction f) { //... class Fraction { int numerator, denominator; // public Fraction(int numerator, int denominator) { // //...
(call by value) (call by reference) main method public public static static void void main(string[] args) args) { // //
main() [ ] java ClassName args1 args2 args3
(overloading void methodover(int i) { /*... */ // void methodover(int i, int j) { /*... */ // [ 5.7] [ 5.8]
(overloading) public class MethodOver { void something() { //... void something(int i) { // void something(int i, int j) { // public static void main(string[] args) { MethodOver m = new MethodOver(); m.something(); m.something(526); m.something(54, 526);
(Constructor) new class Fraction { //... Fraction(int a, int b) { numerator = a; denominator = b; [ 5.9]
(Constructor) Default this()
(Constructor) public class ThisConstructor { ThisConstructor() { System.out.println( Default Constructor ); ThisConstructor(int a) { this(); System.out.println( Constructor with one parameter ); public static void main(string[] args) { ThisConstructor obj = new ThisConstructor(10); System.out.println( End of main );
[1/2] { < >
[2/2] class Initializers { static { i = j + 2; // static int i, j; static j = 4; //...
finalize [1/2] Garbage Collector finalize finalize finalize
finalize [2/2] protected void finalize() throws Throwable { //...
(inner class) [1/2] (information hiding) class OuterClass { //... class InnerClass { //...
(inner class) public static void main(string[] args) { OuterClass outobj = new OuterClass(); OuterClass.InnerClass inobj = outobj.new InnerClass();
.class $.class class Outer { class Inner1 { class Inner2 { // //... //... Outer.class Outer$Inner1.class Outer$Inner1$Inner2.class
, class class Fraction { int intnumerator; // // int intdenominator; // // (,,, ) public public Fraction add(fraction); public public Fraction sub(fraction); public public Fraction mul(fraction); public public Fraction div(fraction); public public String String tostring(); [ 5.17]