0% found this document useful (0 votes)
19 views

Welcome To My Presentation: Instructor Name: S A M Matiur Rahman Department of Software Engineering

The document discusses constructors in Java, including what they are, their properties, types (non-parameterized and parameterized), access modifiers, examples of non-parameterized and parameterized constructors, and advantages of using constructors.

Uploaded by

md anik hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Welcome To My Presentation: Instructor Name: S A M Matiur Rahman Department of Software Engineering

The document discusses constructors in Java, including what they are, their properties, types (non-parameterized and parameterized), access modifiers, examples of non-parameterized and parameterized constructors, and advantages of using constructors.

Uploaded by

md anik hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Welcome to my

presentation

Name: Md. Anik Hasan


ID: 201-35-572 Instructor
Section: PC-A Name: S A M Matiur Rahman
Department of Software Department of Software engineering
Engineering
Topics : Constructor in java
What is Constructor ?

Constructor is a special type method which will be called


automatically when you create an object of any class.

The main purpose of using constructor is to initialize


an object.
Properties of constructor

1. Constructor name must be same as class name

2. Constructor will be called automatically

3. Constructor can’t return any value even void.

4. Constructor should not be static


Type of constructor

 There are 2 types of constructor.


1. Non-Parameterized
2. Parameterized

 Non-Parameterized
Non-Parameterized don't accept values at the time of object creation, but they
can be used to display message.

 Parameterized
Parameterized constructors are the one which helps us to accept values at the
time of object creation.
Access Modifiers in Constructor

Private: The access level of a private modifier is only within the class. It cannot be accessed from outside
the class.

Default: The access level of a default modifier is only within the package. It cannot be accessed from
outside the package. If you do not specify any access level, it will be the default.

Protected: The access level of a protected modifier is within the package and outside the package through
child class. If you do not make the child class, it cannot be accessed from outside the package.

Public: The access level of a public modifier is everywhere. It can be accessed from within the class,
outside the class, within the package and outside the package.
Non-Parameterized Constructor
Non-Parameterized Constructor can be use to display
the message.
Parameterized Constructor
Advantages of constructor

 We don’t have to use object instance for


assigning the values to class variables.

 It helps to reduce LOC(Line of Code)

You might also like