super keyword in java

Solutions on MaxInterview for super keyword in java by the best coders in the world

showing results for - "super keyword in java"
Karl
27 Sep 2020
1ObjMaker = function() {this.a = 'first';};
2// ObjMaker is just a function, there's nothing special about it that makes 
3// it a constructor.
4
5ObjMaker.prototype.b = 'second';
6// like all functions, ObjMaker has an accessible prototype property that 
7// we can alter. I just added a property called 'b' to it. Like 
8// all objects, ObjMaker also has an inaccessible [[prototype]] property
9// that we can't do anything with
10
11obj1 = new ObjMaker();
12// 3 things just happened.
13// A new, empty object was created called obj1.  At first obj1 was the same
14// as {}. The [[prototype]] property of obj1 was then set to the current
15// object value of the ObjMaker.prototype (if ObjMaker.prototype is later
16// assigned a new object value, obj1's [[prototype]] will not change, but you
17// can alter the properties of ObjMaker.prototype to add to both the
18// prototype and [[prototype]]). The ObjMaker function was executed, with
19// obj1 in place of this... so obj1.a was set to 'first'.
20
21obj1.a;
22// returns 'first'
23obj1.b;
24// obj1 doesn't have a property called 'b', so JavaScript checks 
25// its [[prototype]]. Its [[prototype]] is the same as ObjMaker.prototype
26// ObjMaker.prototype has a property called 'b' with value 'second'
27// returns 'second'
Elisa
28 Apr 2016
1Variables and methods of super class can
2be overridden in subclass. 
3In case of overriding , a subclass
4object call its own variables and methods.
5Subclass cannot  access the variables and
6methods of superclass because the overridden
7variables or methods hides the 
8methods and variables of super class.
9But still java provides a way to access 
10super class members even if 
11its members are overridden. Super is
12used to access superclass variables, methods, constructors.
13Super can be used in two forms :
141) First form is for calling super class constructor.
152) Second one is to call super class variables,methods.
16Super if present must be the first statement.
Simone
15 Oct 2016
1**Important Points** 
2
31.It creates a new object. The type of this object is object.
42.It sets this new object's internal, inaccessible, [[prototype]] (i.e. __proto__) property to be the constructor function's external, accessible, prototype object (every function object automatically has a prototype property).
53.It makes the this variable point to the newly created object.
64.It executes the constructor function, using the newly created object whenever this is mentioned.
75.It returns the newly created object, unless the constructor function returns a non-null object reference. In this case, that object reference is returned instead.
8Note: constructor function refers to the function after the new keyword, as in
9
10new ConstructorFunction(arg1, arg2)
Sophia
16 Oct 2017
1Variables and methods of super class can be overridden in subclass. 
2In case of overriding , a subclass
3object call its own variables and methods. Subclass cannot 
4access the variables and methods of
5superclass because the overridden variables or methods hides the 
6methods and variables of super class.
7But still java provides a way to access super class members even if 
8its members are overridden. Super is
9used to access superclass variables, methods, constructors.
10Super can be used in two forms :
111) First form is for calling super class constructor.
122) Second one is to call super class variables,methods.
13Super if present must be the first statement.
similar questions
queries leading to this page
super keyword in java