Skip to content

Commit 5e7d0fe

Browse files
committed
added constructors
1 parent ecd4562 commit 5e7d0fe

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

Java/basics.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
- [Constructors](#constructors)
1010
- [Can the constructor be overridden?](#can-the-constructor-be-overridden)
1111
- [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)
1412
- [Difference between interface & abstract class](#difference-between-interface--abstract-class)
1513
- [Difference between instance variables & local variables](#difference-between-instance-variables--local-variables)
1614
- [Object creation](#object-creation)
1715
- [Access Modifiers](#access-modifiers)
1816
- [Other modifiers](#other-modifiers)
1917
- [Static](#static)
18+
- [Deconstructing the main](#deconstructing-the-main)](#deconstructing-the-maindeconstructing-the-main)
2019
- [Interning](#interning)
2120
- [Mutable & Immutable](#mutable--immutable)
2221
- [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
127126

128127
## Language features
129128
### 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+
130133
### 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+
131136
### 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+
134141
### Difference between interface & abstract class
135142
### Difference between instance variables & local variables
136143
### Object creation
@@ -179,6 +186,8 @@ class StaticSample{
179186

180187
```
181188

189+
### Deconstructing the main](#deconstructing-the-main)
190+
182191
### Interning
183192
String Interning is a method of storing only one copy of each distinct String Value, which must be immutable.
184193

0 commit comments

Comments
 (0)