Search This Blog

Saturday, February 21, 2009

Java First program

/*
In general, class declarations can include these components, in order:

1. Modifiers such as public, private, and a number of others that you will encounter later.
2. The class name, with the initial letter capitalized by convention.
3. The name of the class's parent (superclass), if any, preceded by the keyword extends. A class can only extend (subclass) one parent.
4. A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface.
5. The class body, surrounded by braces, {}.


* public modifier—the field is accessible from all classes.
* private modifier—the field is accessible only within its own class.

*/


public class Notes {
static int x;
int k;

// constructor with 2 args
public Test( int n, int m ) {
x = n;
k = m;
}

public static void main(String[] args) {
Test t1 = new Test(10, 20);
Test t2 = new Test(30, 40);
System.out.print(t1.x + " ");
System.out.print(t1.k + " ");
System.out.print(t2.x + " ");
System.out.println(t2.k);
}
}

No comments:

Post a Comment