Skip to content

Commit 9999321

Browse files
committed
2 parents 4a28127 + f8d162c commit 9999321

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

readme.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ Available in the resources for the course
110110
Wrapper classes in Java are needed for the following reasons:
111111
-
112112
1. **Object-Oriented Programming**: Wrapper classes allow primitive data types to be treated as objects,
113-
enabling
114-
them to be used in object-oriented programming contexts.
113+
enabling them to be used in object-oriented programming contexts.
115114
-
116115
2. **Collections**: Collections in Java, such as `ArrayList`, can only store objects. Wrapper classes allow
117116
primitive types to be stored in collections.
@@ -126,18 +125,20 @@ Available in the resources for the course
126125
type of objects are used.
127126
- **9 . What are the different ways of creating Wrapper class instances?**
128127
There are two main ways to create instances of Wrapper classes in Java:
129-
- 1. **Using Constructors**:
130-
Each wrapper class has a constructor that takes a primitive type or a String as an argument.
131-
```java
132-
Integer intObj1 = 10;
133-
Integer intObj2 = Integer.valueOf("10");
134-
```
135-
- 2. **Using Static Factory Methods**:
136-
The wrapper classes provide static factory methods like `valueOf` to create instances.
137-
```java
138-
Integer intObj1 = 10;
139-
Integer intObj2 = Integer.valueOf("10");
140-
```
128+
-
129+
1. **Using Constructors**:
130+
Each wrapper class has a constructor that takes a primitive type or a String as an argument.
131+
```java
132+
Integer intObj1 = 10;
133+
Integer intObj2 = Integer.valueOf("10");
134+
```
135+
-
136+
2. **Using Static Factory Methods**:
137+
The wrapper classes provide static factory methods like `valueOf` to create instances.
138+
```java
139+
Integer intObj1 = 10;
140+
Integer intObj2 = Integer.valueOf("10");
141+
```
141142
- **10 . What are differences in the two ways of creating Wrapper classes?** \
142143
The two ways of creating Wrapper class instances in Java are using constructors and using static factory methods. Here
143144
are the differences:
@@ -958,18 +959,18 @@ public class Dog implements Animal {
958959

959960
No, this code will not compile due to a missing semicolon at the end of the `System.out.println` statement. In Java,
960961

961-
- **52 . What is the use of this**() keyword in Java?\
962+
- **52 . What is the use of this() keyword in Java?** \
962963
The `this` keyword in Java is a reference to the current object within a method or constructor. It can be used to
963964
access instance variables, call other constructors, or pass the current object as a parameter to other methods. The
964965
use of `this` is optional, but it can help clarify code and avoid naming conflicts between instance variables and
965966
method parameters.
966967

967-
- **53 . Can a constructor be called directly from a method?**\
968+
- **53 . Can a constructor be called directly from a method?** \
968969
No, a constructor cannot be called directly from a method. Constructors are special methods that are called only when
969970
an object is created. However, you can call another constructor from a constructor using `this()` or `super()`. If you
970971
need to initialize an object within a method, you should create a new instance of the class using the `new` keyword.
971972

972-
- **54 . Is a super class constructor called even when there is no explicit call from a sub class constructor?**\
973+
- **54 . Is a super class constructor called even when there is no explicit call from a sub class constructor?** \
973974
Yes, a superclass constructor is always called, even if there is no explicit call from a subclass constructor. If a
974975
subclass constructor does not explicitly call a superclass constructor using `super()`, the Java compiler
975976
automatically inserts a call to the no-argument constructor of the superclass. If the superclass does not have a

0 commit comments

Comments
 (0)