What do we we call a constructor, if it is not a member of a class as stated in Oracle doc: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
-
16What's wrong with just calling it a 'constructor'? – sharakan Jan 24 '13 at 20:20
-
See http://stackoverflow.com/a/1247091/467874 – brabec Jan 24 '13 at 20:21
-
1Any method constructing a class that is not a member of that class, would be a factory, right? – Nick Jan 24 '13 at 20:22
-
+1 @sharakan: What do you call a constructor? A constructor. – Louis Wasserman Jan 24 '13 at 20:22
-
1@Saher ??? ***Constructors are not members**, so they are not inherited by subclasses* – m0skit0 Jan 24 '13 at 20:22
-
@Saher It actually does say that: "Constructors are not members..." – sharakan Jan 24 '13 at 20:23
-
@Nick +1 for that idea :) but isn't the constructor just called after creating the instance, rather than really returning the created instance? so it's not really a factory – Martin Seeler Jan 24 '13 at 20:25
-
@m0skit0 - Static and/or private methods are also not inherited, but they are members. – Ted Hopp Jan 24 '13 at 20:26
-
@TedHopp I'm just quoting Oracle docs about Saher comment. – m0skit0 Jan 24 '13 at 20:28
-
1@Saher no technically you _cannot_ call it a member of the class. The reason is philosophical, you cannot create something being INSIDE(member) of it. Because technically it doesn't exist until its created ../ chicken egg problem? – Aniket Inge Jan 24 '13 at 20:34
-
Constructors are not typical methods like the others. It's just called "Constructor". If you understand what it is used for, you won't be surprised that it is NOT a class member. – shuangwhywhy Jan 24 '13 at 20:48
-
You don't invoke a "Constructor" anytime, you just invoke it when you try to build an object. Only after an object is "constructed", its non-static "members" can be used. – shuangwhywhy Jan 24 '13 at 20:51
-
I realize I held onto a stupid thought of constructor being a member. My bad. – Saher Ahwal Jan 24 '13 at 23:46
-
@shuangwhywhy Not entirely. Members can also be used **while the instance is being constructed**, for example `SomeClass() { someOtherMethod(); }`. – MC Emperor Jul 02 '17 at 20:07
6 Answers
I think the term "member" was defined to exclude constructors for the sake of convenience. Constructors, even public ones, are not inherited; members are inherited (unless they are static and/or private). It would be awkward when talking about the rules of inheritance to always have to say "members except constructors".
From the Java Language Specification, §8.2:
Constructors, static initializers, and instance initializers are not members and therefore are not inherited.
Just call constructors "constructors".

- 232,168
- 48
- 399
- 521
-
also note, unlike regular methods, constructors have no return typee – Aniket Inge Jan 24 '13 at 20:25
Its a special method that every class has, which is called after creation of the object. in JVM its called using invokespecial
so, lets just call it a special
method?
And since there is just 1 special method in Java - they all call it "constructor"

- 25,375
- 5
- 50
- 78
-
3Constructors are not methods. From the [JLS, §8](http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html): _"Constructors are similar to methods, but cannot be invoked directly by a method call; they are used to initialize new class instances."_ – Ted Hopp Jan 24 '13 at 20:42
-
@TedHopp a normal method call translates to `invokevirtual` or `invokestatic` opcode. "Note that **methods** called using the invokespecial instruction always pass this to the invoked **method** as its first argument. As usual, it is received in local variable 0." - from JVM Specification. – Aniket Inge Jan 24 '13 at 20:50
-
1The term "method" has a very specific technical meaning within the JLS. There's no reason to confuse Java language terminology with that of the Java virtual machine. The JLS makes clear that constructors and methods are different things. Calling a c'tor a "special method" serves only to blur a distinction that the JLS goes to the effort of making. A c'tor is not a "special method" (which term does not appear in the JLS); it's a c'tor. To put it another way: the compiler turns a c'tor into an `
` method, but a Java language c'tor and a JVM ` – Ted Hopp Jan 25 '13 at 02:44` method are different things. -
I'm surprised to see so many answers here saying that constructors are methods or a special kind of method, when the language specification goes out of its way a million times to say that they are NOT. Can't be any clearer. Funny that people just don't care. People are like that I guess. They use their own definitions because they are right and the language designers are wrong. :) Thanks to @TedHopp for the many citations to help clarify. – Ray Toal Mar 25 '16 at 01:19
-
@RayToal I hardly believe the "official documentation" - I have time and again proved the documentation is updated by a different individual than the individual writing the code. Happens almost always. It's always good to look at code below the hood. – Aniket Inge Mar 25 '16 at 17:07
All the doc is saying is that the constructor is not inherited by default. Since the constructor is a method that is invoked on the construction of the object in the memory heap, then once you create a subclass that inherits from a super class, the constructor of the super class is not invoked by default.
For instance if you have a class Vehicle
and a subclass Car
, assume the Vehicle
constructor is as follows:
public Vehicle(String vehName) {
this.vehName = vehName;
}
Then, even though your class Car
inherits from class Vehicle
, the vehName
member (field) will not be set as the constructor above does.
So you will need to do something like this:
public Car(String vehName) {
super(vehName);
}
Hope that helps

- 22,334
- 15
- 80
- 130

- 9,015
- 32
- 84
- 152
In Java, a class body (the area between braces) can contain the following key items: (1) Fields (2) Methods (3) Other Classes (nested classes) (4) Constructors (5) Initializers
An object created from a particular class shall take the shape that is similar to the blueprint (class) from which it's created. Now, if you look at items that can be contained in a class body, only item (1) to (3) help in determining what sort of object can be created from a particular class definition.
Constructors and initializers only play part in actual creation of the object (e.g. initialization of already defined fields), but do not determine what shape/state that object shall carry, and what behaviors it will display.
For this reason, to me, it make sense to call item (1) to (3) class members (i.e. class members are those items within a class body that determine how an object created from the class looks like and behave); whereas constructors and initializers are not members because their absence in a class definition does not affect a class state and behavior.
As such, only class members can be inherited as the whole point behind inheritance is to enable a subclass reuse state and behavior of its superclass.

- 47
- 1
- 1
- 5
A Constructor is a method which is in a class which is used to create a new instance of that class. Being a member of a class just means that the item in question is in the class.

- 105
- 1
- 6
-
-
3Constructors are not methods. See the [Java Language Specification, §8](http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html): _"Constructors are similar to methods, but cannot be invoked directly by a method call; they are used to initialize new class instances."_ – Ted Hopp Jan 24 '13 at 20:45
-
1Constructor does not create new instance of class. Constructor is special method that is used to set-up (initialize) object created with `new` operator. – Pshemo Jan 24 '13 at 21:22
Constructor is a method which name is same as the class. It is used to initialize the object of class. It's implicit in action. Parametric constructor initialize object with different value.
-
1Constructors are not methods. [It says so explicitly in the Language Specification](http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html). – Ray Toal Mar 25 '16 at 01:15