James PK's Technical Journal

[ Home | Journal ]

Sun, 14 Sep 2014

Java - Basic Example - Inheritance, Overriding, Vectors, Constructors

I needed to recap my Java knowledge recently. Here are snippets of a very basic example I wrote re-familiarise myself with Java.

Inheritance: The extends keyword is used:
class Car extends MotorVehicle {
Constructors: Which constructor is used depends on the argument to the constructor:
	MotorVehicle (String mType){
	MotorVehicle (){
Overriding: overriding a method:
        public String toString() {
        	return mType + " " + maxSpeed;

Collections: A basic example of using a vector to store objects and retrieve:
    Vector  mvs = new Vector(5);


    for (int i = 0;i < mvs.size();i++) {

posted at: 00:00 | path: /java | permanent link to this entry

Made with Pyblosxom