0

Can anyone explain about constructors in java

I want to learn about constructors. please answer me.

26th Sep 2017, 11:56 AM
Gowtham Saravanan
Gowtham Saravanan - avatar
2 Réponses
+ 3
Constructors are basically a way to create an instance of an object meaning it makes the object itself you can say lets say i have a blueprint of a car (my code) i cannot use the car because i have not made it yet. thats where constructors are used. i need to build the car first than i can call its fuctions or methods. you can make as much of one object as you like using constructors. like normal methods you can add paramaters to it so that you can make your object with specified variables like, for example defining coordinates for an entity in a game to spawn at note: all classes have constructors weather you define them or not i usally use constructors to avoid static methods my main class for example public class Hello { public static void main(String[] args) { new Hello().run() } public void run() { //code here } } this is just so I can pass over from a static to an instance so all my class variables in this class are not static variables. this is really only the surface of constructors and you really should learn more about them by using them and find how they are useful happy coding
26th Sep 2017, 12:20 PM
SomeoneAwesome78
SomeoneAwesome78 - avatar
- 1
the a lot brother
26th Sep 2017, 2:56 PM
Gowtham Saravanan
Gowtham Saravanan - avatar