Programming - Java - Classes


Java is a very powerful OO language. It is based on tried and tested OO techniques and uses standard OO naming and access constraints.

class YourClass {

declare your fields, constructor, and methods here

}

class SubAndExtendedClass extends YourSuperClass implements AnInterface {

declare your fields, constructor, and methods here

}

A variable is defined as so:

public int MyInt;

A method is an operation that can be performed on an object:

public int getMyInt() {

return MyInt;

}

public bool MySetMyInt(int MyInt) {

this.MyInt = MyInt;

return true;

}


You should use 'this' to access all fields and members in a particular class object. This will only work for instance objects and not static objects.

There are also:

public

private

protected

Access which is applied to every field in class, either explicitly by yourself or implicitly by the compiler if you choose not to define it.

At the member level, you can use the public modifier or no modifier (package-private) just as with top-level classes, and with the same meaning. For members, there are two additional access modifiers: private and protected. The private modifier specifies that the member can only be accessed in its own class. The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.

Home | Privacy Policy | Site Map | Links | Company | Contact Us | Arena           

We provide cutting edge software development, consultancy and web design services            

There are currently 650 user(s) with 40879 hits.