+ 2

What is the difference between class and a constructor?!

constructor in java

7th Feb 2017, 3:47 PM
krishna bhargava
krishna bhargava - avatar
6 ответов
+ 1
in simple words a class is like a blueprint and defines the framework that other objects can inherit, a constructor is something that actually creates the object in the program whereas the class only gives the guidelines.
7th Feb 2017, 3:52 PM
Sanchit Pandey
Sanchit Pandey - avatar
0
@Sanchit Stone, I would not use that for the definition of class, even in simple words. Class DEFINITELY IS NOT an object and you should not think about classes in that way.. In simple words class is a blueprint for creating an object and constructor is special kind of a method that creates objects. Imagine a house. The architect draws a blueprint for that house - that is your class. If you have that blueprint you just need some lot (that is your memory) and you have to call constructors to make the house from that blueprint (actual object of that class). And if you have that blueprint you can make as many houses that you want if you have more lots and if you call constructors to build it. Little closer to programming world: You should look at class as a data type. As you have type of integer (so that is actual representation of what it stores) and you can assign some value to it (like int i = 5) You can have class, for example Point that can store some value of Point data type like Point p = new Point(2,5); And with writing "new Point(2,5)" you are actually calling the constructor and passing it some values. I hope this answers your question. :)
7th Feb 2017, 4:29 PM
Ladislav Milunović
Ladislav Milunović - avatar
0
I said that only read my full answer I said that a class lays down the guidelines for the objects to inherit it.
7th Feb 2017, 4:30 PM
Sanchit Pandey
Sanchit Pandey - avatar
0
@Sanchit Stone I've read your answer several times and I understood what you wanted to say. Your explanation isn't exact, and programming is nothing but the exact thing. "------>in simple words a class is a object<------- and defines the framework that other items can inherit, a constructor is something that actually creates the object in the program whereas the class only gives the guidelines." It is not an object. "I said that only read my full answer I said that a class lays down the guidelines for the ------>objects to inherit it<-------." And objects DOES NOT inherit classes. Objects are instances of classes they belong to. I know what you wanted to say but you are using bad words to express yourself and that can lead to confusion for people you try to explain something and because of that they can learn and understand something WRONG. If you are a programmer you should express like one. Peace to you and keep coding.
7th Feb 2017, 5:08 PM
Ladislav Milunović
Ladislav Milunović - avatar
0
What does a constructor? Is that the part where I build my object in the Programme or is that another stuff? When do I need to transfer parameters in a constructor? ( sorry beginner :D)
7th Feb 2017, 8:40 PM
Marco
Marco - avatar
0
@Marco, read my answer please I tried to explain as clear as possible. "Constructor is special method that creates objects of particular class" If you read my answer carefully (there are 2 of them you will realize which one) and after that take a look at this code, you should be able to understand: https://code.sololearn.com/cqvgS8d6n4gS/#java
7th Feb 2017, 9:30 PM
Ladislav Milunović
Ladislav Milunović - avatar