Skip to content

Commit 4818727

Browse files
authored
Update README.md
1 parent e763b55 commit 4818727

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

README.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -508,22 +508,25 @@
508508
[abstraction](https://en.wikipedia.org/wiki/Abstraction_(software_engineering)), and
509509
[encapsulation](https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)).
510510

511-
* **What is the difference between a constructor and a method?**
511+
* **What is the difference between a constructor and a method?**
512+
- The name of the constructor is same as that of the class name, whereas the name of the method can be anything.
513+
- There is no return type of a constructor.
514+
- When you make an object of a class, then the constructor of that class will be called automatically.
515+
But for methods, we need to call it explicitely.
516+
- Constructors can't be inherited but you can call the constructor of the parent class by calling `super()`.
512517
- Constructor and a method they both run a block of code but the difference is in calling them.
513-
- Constructor gets called automatically when we create an object of that class, we cannot call it explicitly
514-
though we can call parent class constructor using 'super' keyword.
515-
- We call method directly using their name.
518+
- We can call method directly using their name.
516519
- Constructor Syntax -
517520
public class SomeClass{
518521
SomeClass(parameter_list){
519522
...
520523
}
521524
...
522525
}
523-
Note:
524-
Constructor name is the same as class name
525-
Constructor does not have return type
526-
526+
- Note:
527+
Constructor name is the same as class name
528+
Constructor does not have return type
529+
527530
- Method Syntax
528531
public class SomeClass{
529532
public void someMethod(parameter_list){
@@ -532,12 +535,6 @@ Constructor does not have return type
532535
// call method
533536
someMethod(parameter_list)
534537
}
535-
536-
- Name of the method can be anything.
537-
- When you make an object of a class, then the constructor of that class will be called automatically.
538-
But for methods, we need to call it explicitely.
539-
- Constructors can't be inherited but you can call the constructor of the parent class by calling `super()`.
540-
541538
* **Differences between abstract classes and interfaces?**
542539
- An abstract class, is a class that contains both concrete and abstract methods
543540
(methods without implementations). An abstract method must be implemented by the abstract class

0 commit comments

Comments
 (0)