class definition
You are here :

Sub nodes

Recent changes
Site plan
 
This page is not available in requested lang, reverting to default lang
 

Class

Here's the syntax :

 [public] [abstract] class ClassName [ extends TypeName ] [ implements TypeName (, TypeName)* ] {
 }

Example :

 public class Car implements Vehicule {
 }

By default a class has a 'package' scope. That is, the class is only accessible by the classes located in the same package. Adding the 'public' keyword in front of it will enable the class to be seen by all other classes in all packages.

By default, all members in a class are package. You have to use the keywords [public, protected, private] to change their scope.

Example :

 public class Car implements Vehicule {
   private string model;
   private Color color;
   // a public constructor
   public constructor(string model, Color color) {
     this.model = model;
     this.color = color;
   }
   public String getModel() const { return model; }
   public Color getColor() const { return color; }
 }

Interface

Here's the syntax :

 [public] interface ClassName [ implements TypeName (, TypeName)* ] {
 }

Example :

 public interface Vehicule {
   String getModel() const;
   Color getColor() const;
 }

As classes, the default scope of an interface is the package scope. The scope of all methods declared in an interface is public. You cannot change it.

Propulsed by Wiclear