|
9 | 9 | - [Constructors](#constructors) |
10 | 10 | - [Can the constructor be overridden?](#can-the-constructor-be-overridden) |
11 | 11 | - [Difference between overloading and overriding?](#difference-between-overloading-and-overriding) |
12 | | - - [Deconstructing the main](#deconstructing-the-main)](#deconstructing-the-maindeconstructing-the-main) |
13 | | - - [Accessing non-static member from static method](#accessing-non-static-member-from-static-method) |
14 | 12 | - [Difference between interface & abstract class](#difference-between-interface--abstract-class) |
15 | 13 | - [Difference between instance variables & local variables](#difference-between-instance-variables--local-variables) |
16 | 14 | - [Object creation](#object-creation) |
17 | 15 | - [Access Modifiers](#access-modifiers) |
18 | 16 | - [Other modifiers](#other-modifiers) |
19 | 17 | - [Static](#static) |
| 18 | + - [Deconstructing the main](#deconstructing-the-main)](#deconstructing-the-maindeconstructing-the-main) |
20 | 19 | - [Interning](#interning) |
21 | 20 | - [Mutable & Immutable](#mutable--immutable) |
22 | 21 | - [StingBuilder vs StringBuffer and immutability](#stingbuilder-vs-stringbuffer-and-immutability) |
@@ -127,10 +126,18 @@ Since Java is a Object Oriented language, in order to utilize the Object level f |
127 | 126 |
|
128 | 127 | ## Language features |
129 | 128 | ### Constructors |
| 129 | +Constructors are special methods that are invoked during the object creation. Constructors look like normal methods except that they do return anything. |
| 130 | + |
| 131 | +By default all the Classes will have a default constuctor which takes no arguments. If we create any new constructor for a class with arguments, that will become the default constructor. i.e. Whenever we create an object of the class using `new` operator, the arguments should be passed. We can override this by providing an additional constructor with no argument. A class can have any number of constructors. We can use access modifiers on the constructors to set the access on who can instantiate the class (or create the object). |
| 132 | + |
130 | 133 | ### Can the constructor be overridden? |
| 134 | +No. Overriding happens when a subclass has the same name, number/type of parameters, and the same return type as an instance method of the superclass. But constructors are special methods that are assigned to a class to be invoked during Object creation. Similarly they can not be inherited, though it can be accessed using `super`. |
| 135 | + |
131 | 136 | ### Difference between overloading and overriding? |
132 | | -### Deconstructing the main](#deconstructing-the-main) |
133 | | -### Accessing non-static member from static method |
| 137 | +Overloading - When two or more methods in a class have the same method name but different parameters. |
| 138 | + |
| 139 | +Overriding - Having two methods with the same method name and parameters (i.e., method signature). This will be used between parent and subclasses. Where a subclass can override the method available in the parent to modify the purpose of the method. The actual method can always be called from the subclass using `super` |
| 140 | + |
134 | 141 | ### Difference between interface & abstract class |
135 | 142 | ### Difference between instance variables & local variables |
136 | 143 | ### Object creation |
@@ -179,6 +186,8 @@ class StaticSample{ |
179 | 186 |
|
180 | 187 | ``` |
181 | 188 |
|
| 189 | +### Deconstructing the main](#deconstructing-the-main) |
| 190 | + |
182 | 191 | ### Interning |
183 | 192 | String Interning is a method of storing only one copy of each distinct String Value, which must be immutable. |
184 | 193 |
|
|
0 commit comments