Object Oriented Programming

Instantiation in Java

Instantiation is used to create an object instance from a class (instantiate).


Syntax
className objectName = new className(inputParameters);

Notes

Input requirements are taken from the constructor. A class can have multiple constructors with different numbers of input parameters and types, to create different objects.

An instance of a class is called an object.


Example
//class looks like this
public class Car {
    String make;
    public Car(string make) {
        this.make = make;
    }
}

//instantiation, elsewhere in the program
Car myCar = new Car("Honda"); //passing in Honda into the make variable

See Also
Documentation

Creating Objects - Java Tutorial

Add to Slack

< Constructor   |   Class Variables >

© 2019 SyntaxDB. All Rights Reserved.