GoConqr has a new look! Let us know what you think.

Flashcards

Constructor

BLU BLU German 7 cards

Cards in this deck (7)

  1. 1What is a Constructor?A special type of method with no return type which used for initializing the object
    - When Object gets created, the Constructor gets invoked and the object is allocated memory in heap area.
    - It passes the values i.e. initialize values for the objects variables. The instance variables will get the default values based on their data types.
    - Constructor name is the same like the class
    - no return type
    - cant use abstract, static, final and synchronized
  2. 2Which types of constructors exist?- Default Constructor
    - Non- Parameterized Constructor
    -Parameterized Constructor
  3. 3How does the default Constructor works?With the new() keyword an Object will be created and at least one constructor will be called by JVM.
    If there is no explicit Constructor defined the compiler envoque default constructor
    Default constructor will initialize default values for the object depending upon instance variable data type for example 0, null etc
  4. 4Whats the difference between a non-parameterized and a parameterized constructor?non Parameterized Constructor:
    - A Constructor having no parameters but you can initialize the instance variable with hard coded values
    - Used to provide same values to distinct objects
    Parameterized Constructor:
    - A Constructor having parameters
    - Used to initialize different values to unique objects
  5. 5What is forcing Constructor Overloading?- same name and a different set of arguments
    - Ways to achieve Polymorphism
  6. 6What is the difference between Constructors and Methods? 6 Punkte- Constructor is used for initializing the state of an object
    - Methods expose the behavior of an object
    Constructors have no return type and methods can have one
    Constructors are implicitly invoked during object creation and Methods explicitly during Method call
    - Default constructor will be provided by the compiler if not present
    Methods need to be created explicitly by users.
    Constructors name should be the same than the class name and methods name don't need to be
  7. 7What are the rules about constructor? 6 Punkte- Constructor name same like class name
    - no return type
    - not abstract, static, final and synchronized
    - not inherited but can be overloaded
    - The compiler wont generate the default constructor if theres already a constructor in the class.
    - The default constructor has the same access modifier as the class

Information

Description
Flashcards on Constructor, created by BLU BLU on 22/01/2025.
Created by
BLU BLU
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?