Constructor
A constructor is a special method for initializing a new instance of a class.
The constructor method for a class will have the same name as the class.
Constructor Example
This example shows a class and a constructor named Circle:
public class Circle {
public int x = 0;
public int y = 0;
public int radius = 0;
public Circle(int x, int y, int radius) {
this.x = x;
this.y = y;
this.radius = radius;
}
}
A class may have multiple constructors. In this case, each constructor will have the same name, but will have different arguments.
A no-argument constructor is a constructor which does not take any arguments.
- Java Method
A Java method is a set of Java statements that can be included inside a Java class. Java methods are similar to functions or procedures in other programming languages. There are many different types of Java methods: Final Method Public Method Private Method Package Method Instance Method Protected Method Static Method Main Method The Main [...]...
- Java Class
A Java class is a group of Java methods and variables. Each Java source code file can contain one public class. The name of this public class must match the name of the Java source code file. If the public class is called “ballistics,” then the filename would be “ballistics.java.” Example Java Class class Ammunition [...]...
- Object
A Java object is a set of data combined with methods for manipulating that data. An object is made from a class; a class is the blueprint for the object. Each object made from a class will have its own values for the instance variables of that class. Instance variables are things an object knows [...]...





