2.1_Creating Objects Flashcards
How to declare variables in Java?
{Type} varName;
Where fields can be initialized?
Fields can be initialized: o Inline (At the same line of its declaration) o or via Constructor
What is the syntax to declare a Constructor?
o It should matches the class-name
o there’s 👀️⚠️NO return type⚠️👀️.
What could be called a fake Constructor?
🤯️⚠️ When you see a method name which matches the name of the class but ❌having a return type❌
🤯️📣️Pay special attention to it. It is not a constructor since there’s a return type.
When does the compiler provides the default constructor?
If no other constructors are available in the class, the compiler will supply a “do nothing” default constructor for you.
⚠️(There are some scenarios that do require you declare a constructor.)