SlideShare a Scribd company logo
CONSTRUCTOR
S.G.V.P.Gunasekara - 2015238
1
Constructor
Constructor in java is a special type of method that is used to initialize the
object.
Java constructor is invoked at the time of object creation. It constructsthe
values i.e. provides data for the object that is why it is known as
constructor.
2
Rules for creating java constructor
There are basically two rules defined for the constructor.
1. Constructor name must be same as its classname
2. Constructor must have no explicit returntype
3
Types of java constructors
There are two types of constructors:
1. Default constructor (no-arg constructor)
2. Parameterizedconstructor
4
Default constructor
class. It will be invoked at the
A constructor that have no parameter is known as defaultconstructor.
Syntax of default constructor:
<class_name>(){}
Example of default constructor
In this example, we are creating the no-arg constructor in theBike
time of object creation.
class Bike1{
Bike1(){
System.out.println(&quot;Bike is created&quot;)
;}
public static void main(Stringargs[]){
Bike1 b=new Bike1();
}
}
5
Parameterized constructor
A constructor that have parameters is known as parameterizedconstructor.
Why use parameterized constructor?
Parameterized constructor is used to provide different values to
the distinct objects.
6
 Example of parameterized constructor
In this example, we have created the constructor of Student class that have two parameters.
We can have any number of parameters in the constructor.
class Student4{
int id;
String name;
Student4(int i,String n){
id = i;
name = n;
}
void display(){System.out.println(id+&quot; &quot;+name);}
public static void main(String args[]){
Student4 s1 = new Student4(111,&quot;Karan&quot;);
Student4 s2 = new Student4(222,&quot;Aryan&quot;);
s1.display();
s2.display();
}
}
7
Output:
111 Karan
222 Aryan
8
Constructor overloading
Like other methods in java constructor can be overloaded i.e. we can
create asmany constructors in our class asdesired. Number of
constructors depends on the information about attributes of an objectwe
have while creating objects.
9
example: constructor overloading example:
classLanguage{
String name;
Language() {
System.out.println("Constructor methodcalled.");
}
Language(String t) {
name = t;
}
public static void main(String[] args) {
Language cpp = new Language();
Language java = new Language("Java");
cpp.setName("C++");
java.getName();
cpp.getName();
}
void setName(String t) {
name = t;
}
void getName() {
System.out.println("Language name: " + name);
}
}
10
Output:
Constructor method called.
Language name: java
Language name:c++
11
12
Ad

More Related Content

What's hot (20)

ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
Atul Sehdev
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Vineeta Garg
 
[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance
Muhammad Hammad Waseem
 
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Abu Saleh
 
Dagger1
Dagger1Dagger1
Dagger1
Ramesh Akula
 
Class notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methodsClass notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methods
Kuntal Bhowmick
 
ConsTRUCTION AND DESTRUCTION
ConsTRUCTION AND DESTRUCTIONConsTRUCTION AND DESTRUCTION
ConsTRUCTION AND DESTRUCTION
Shweta Shah
 
Constructor destructor.ppt
Constructor destructor.pptConstructor destructor.ppt
Constructor destructor.ppt
Karthik Sekar
 
An introduction to constructor
An introduction to constructorAn introduction to constructor
An introduction to constructor
Niby Babu
 
Pavel kravchenko obj c runtime
Pavel kravchenko obj c runtimePavel kravchenko obj c runtime
Pavel kravchenko obj c runtime
DneprCiklumEvents
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
Raja Sekhar
 
Functions and Objects in JavaScript
Functions and Objects in JavaScript Functions and Objects in JavaScript
Functions and Objects in JavaScript
Dhananjay Kumar
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
Hazem Hagrass
 
C++ classes
C++ classesC++ classes
C++ classes
Aayush Patel
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
Rai University
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
Vineeta Garg
 
19 reflection
19   reflection19   reflection
19 reflection
dhrubo kayal
 
Ian 2014.10.24 weekly report
Ian 2014.10.24 weekly reportIan 2014.10.24 weekly report
Ian 2014.10.24 weekly report
LearningTech
 
Constructor&method
Constructor&methodConstructor&method
Constructor&method
Jani Harsh
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
rajveer_Pannu
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
Atul Sehdev
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Vineeta Garg
 
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Abu Saleh
 
Class notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methodsClass notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methods
Kuntal Bhowmick
 
ConsTRUCTION AND DESTRUCTION
ConsTRUCTION AND DESTRUCTIONConsTRUCTION AND DESTRUCTION
ConsTRUCTION AND DESTRUCTION
Shweta Shah
 
Constructor destructor.ppt
Constructor destructor.pptConstructor destructor.ppt
Constructor destructor.ppt
Karthik Sekar
 
An introduction to constructor
An introduction to constructorAn introduction to constructor
An introduction to constructor
Niby Babu
 
Pavel kravchenko obj c runtime
Pavel kravchenko obj c runtimePavel kravchenko obj c runtime
Pavel kravchenko obj c runtime
DneprCiklumEvents
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
Raja Sekhar
 
Functions and Objects in JavaScript
Functions and Objects in JavaScript Functions and Objects in JavaScript
Functions and Objects in JavaScript
Dhananjay Kumar
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
Rai University
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
Vineeta Garg
 
Ian 2014.10.24 weekly report
Ian 2014.10.24 weekly reportIan 2014.10.24 weekly report
Ian 2014.10.24 weekly report
LearningTech
 
Constructor&method
Constructor&methodConstructor&method
Constructor&method
Jani Harsh
 

Similar to Constructor oopj (20)

Constructor in java
Constructor in javaConstructor in java
Constructor in java
Madishetty Prathibha
 
Constructors in Java (2).pdf
Constructors in Java (2).pdfConstructors in Java (2).pdf
Constructors in Java (2).pdf
kumari36
 
constructors.pptx
constructors.pptxconstructors.pptx
constructors.pptx
Epsiba1
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
chauhankapil
 
Constructors In Java – Unveiling Object Creation
Constructors In Java – Unveiling Object CreationConstructors In Java – Unveiling Object Creation
Constructors In Java – Unveiling Object Creation
Geekster
 
Week 3-LectureA Object Oriented Programmings.pptx
Week 3-LectureA Object Oriented Programmings.pptxWeek 3-LectureA Object Oriented Programmings.pptx
Week 3-LectureA Object Oriented Programmings.pptx
FarhanGhafoor7
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
Chapter 7 - Constructors.pptx
Chapter 7 - Constructors.pptxChapter 7 - Constructors.pptx
Chapter 7 - Constructors.pptx
KavitaHegde4
 
Chapter 7 - Constructors.pdf
Chapter 7 - Constructors.pdfChapter 7 - Constructors.pdf
Chapter 7 - Constructors.pdf
KavitaHegde4
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
SIVASHANKARIRAJAN
 
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCECONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
UNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptxUNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptx
shilpar780389
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
DrYogeshDeshmukh1
 
Java Constructor
Java ConstructorJava Constructor
Java Constructor
MujtabaNawaz4
 
A constructor in Java is a special method that is used to initialize objects
A constructor in Java is a special method that is used to initialize objectsA constructor in Java is a special method that is used to initialize objects
A constructor in Java is a special method that is used to initialize objects
Kavitha S
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
madhavi patil
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
sunilchute1
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptx
akila m
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Prof. Dr. K. Adisesha
 
1_JavIntro
1_JavIntro1_JavIntro
1_JavIntro
SARJERAO Sarju
 
Constructors in Java (2).pdf
Constructors in Java (2).pdfConstructors in Java (2).pdf
Constructors in Java (2).pdf
kumari36
 
constructors.pptx
constructors.pptxconstructors.pptx
constructors.pptx
Epsiba1
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
chauhankapil
 
Constructors In Java – Unveiling Object Creation
Constructors In Java – Unveiling Object CreationConstructors In Java – Unveiling Object Creation
Constructors In Java – Unveiling Object Creation
Geekster
 
Week 3-LectureA Object Oriented Programmings.pptx
Week 3-LectureA Object Oriented Programmings.pptxWeek 3-LectureA Object Oriented Programmings.pptx
Week 3-LectureA Object Oriented Programmings.pptx
FarhanGhafoor7
 
Chapter 7 - Constructors.pptx
Chapter 7 - Constructors.pptxChapter 7 - Constructors.pptx
Chapter 7 - Constructors.pptx
KavitaHegde4
 
Chapter 7 - Constructors.pdf
Chapter 7 - Constructors.pdfChapter 7 - Constructors.pdf
Chapter 7 - Constructors.pdf
KavitaHegde4
 
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCECONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
UNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptxUNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptx
shilpar780389
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
DrYogeshDeshmukh1
 
A constructor in Java is a special method that is used to initialize objects
A constructor in Java is a special method that is used to initialize objectsA constructor in Java is a special method that is used to initialize objects
A constructor in Java is a special method that is used to initialize objects
Kavitha S
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
madhavi patil
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
sunilchute1
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptx
akila m
 
Ad

More from ShaishavShah8 (19)

Diffie hellman key algorithm
Diffie hellman key algorithmDiffie hellman key algorithm
Diffie hellman key algorithm
ShaishavShah8
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
ShaishavShah8
 
Classification of debuggers sp
Classification of debuggers spClassification of debuggers sp
Classification of debuggers sp
ShaishavShah8
 
Parallel and perspective projection in 3 d cg
Parallel and perspective projection in 3 d cgParallel and perspective projection in 3 d cg
Parallel and perspective projection in 3 d cg
ShaishavShah8
 
Asymptotic notations ada
Asymptotic notations adaAsymptotic notations ada
Asymptotic notations ada
ShaishavShah8
 
Arrays in java oopj
Arrays in java oopjArrays in java oopj
Arrays in java oopj
ShaishavShah8
 
Classical cyphers python programming
Classical cyphers python programmingClassical cyphers python programming
Classical cyphers python programming
ShaishavShah8
 
Logics for non monotonic reasoning-ai
Logics for non monotonic reasoning-aiLogics for non monotonic reasoning-ai
Logics for non monotonic reasoning-ai
ShaishavShah8
 
Rdd transformations bda
Rdd transformations bdaRdd transformations bda
Rdd transformations bda
ShaishavShah8
 
Introduction to data warehouse dmbi
Introduction to data warehouse dmbiIntroduction to data warehouse dmbi
Introduction to data warehouse dmbi
ShaishavShah8
 
Lan, wan, man mcwc
Lan, wan, man mcwcLan, wan, man mcwc
Lan, wan, man mcwc
ShaishavShah8
 
Introduction to xml, uses of xml wt
Introduction to xml, uses of xml wtIntroduction to xml, uses of xml wt
Introduction to xml, uses of xml wt
ShaishavShah8
 
Agile process se
Agile process seAgile process se
Agile process se
ShaishavShah8
 
Applications of huffman coding dcdr
Applications of huffman coding dcdrApplications of huffman coding dcdr
Applications of huffman coding dcdr
ShaishavShah8
 
Cookie management using jsp a java
Cookie management using jsp  a javaCookie management using jsp  a java
Cookie management using jsp a java
ShaishavShah8
 
Login control .net
Login control .netLogin control .net
Login control .net
ShaishavShah8
 
Rdd transformations
Rdd transformationsRdd transformations
Rdd transformations
ShaishavShah8
 
LAN, WAN, MAN
LAN, WAN, MANLAN, WAN, MAN
LAN, WAN, MAN
ShaishavShah8
 
Introduction to data warehouse
Introduction to data warehouseIntroduction to data warehouse
Introduction to data warehouse
ShaishavShah8
 
Diffie hellman key algorithm
Diffie hellman key algorithmDiffie hellman key algorithm
Diffie hellman key algorithm
ShaishavShah8
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
ShaishavShah8
 
Classification of debuggers sp
Classification of debuggers spClassification of debuggers sp
Classification of debuggers sp
ShaishavShah8
 
Parallel and perspective projection in 3 d cg
Parallel and perspective projection in 3 d cgParallel and perspective projection in 3 d cg
Parallel and perspective projection in 3 d cg
ShaishavShah8
 
Asymptotic notations ada
Asymptotic notations adaAsymptotic notations ada
Asymptotic notations ada
ShaishavShah8
 
Classical cyphers python programming
Classical cyphers python programmingClassical cyphers python programming
Classical cyphers python programming
ShaishavShah8
 
Logics for non monotonic reasoning-ai
Logics for non monotonic reasoning-aiLogics for non monotonic reasoning-ai
Logics for non monotonic reasoning-ai
ShaishavShah8
 
Rdd transformations bda
Rdd transformations bdaRdd transformations bda
Rdd transformations bda
ShaishavShah8
 
Introduction to data warehouse dmbi
Introduction to data warehouse dmbiIntroduction to data warehouse dmbi
Introduction to data warehouse dmbi
ShaishavShah8
 
Introduction to xml, uses of xml wt
Introduction to xml, uses of xml wtIntroduction to xml, uses of xml wt
Introduction to xml, uses of xml wt
ShaishavShah8
 
Applications of huffman coding dcdr
Applications of huffman coding dcdrApplications of huffman coding dcdr
Applications of huffman coding dcdr
ShaishavShah8
 
Cookie management using jsp a java
Cookie management using jsp  a javaCookie management using jsp  a java
Cookie management using jsp a java
ShaishavShah8
 
Introduction to data warehouse
Introduction to data warehouseIntroduction to data warehouse
Introduction to data warehouse
ShaishavShah8
 
Ad

Recently uploaded (20)

Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 

Constructor oopj

  • 2. Constructor Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructsthe values i.e. provides data for the object that is why it is known as constructor. 2
  • 3. Rules for creating java constructor There are basically two rules defined for the constructor. 1. Constructor name must be same as its classname 2. Constructor must have no explicit returntype 3
  • 4. Types of java constructors There are two types of constructors: 1. Default constructor (no-arg constructor) 2. Parameterizedconstructor 4
  • 5. Default constructor class. It will be invoked at the A constructor that have no parameter is known as defaultconstructor. Syntax of default constructor: <class_name>(){} Example of default constructor In this example, we are creating the no-arg constructor in theBike time of object creation. class Bike1{ Bike1(){ System.out.println(&quot;Bike is created&quot;) ;} public static void main(Stringargs[]){ Bike1 b=new Bike1(); } } 5
  • 6. Parameterized constructor A constructor that have parameters is known as parameterizedconstructor. Why use parameterized constructor? Parameterized constructor is used to provide different values to the distinct objects. 6
  • 7.  Example of parameterized constructor In this example, we have created the constructor of Student class that have two parameters. We can have any number of parameters in the constructor. class Student4{ int id; String name; Student4(int i,String n){ id = i; name = n; } void display(){System.out.println(id+&quot; &quot;+name);} public static void main(String args[]){ Student4 s1 = new Student4(111,&quot;Karan&quot;); Student4 s2 = new Student4(222,&quot;Aryan&quot;); s1.display(); s2.display(); } } 7
  • 9. Constructor overloading Like other methods in java constructor can be overloaded i.e. we can create asmany constructors in our class asdesired. Number of constructors depends on the information about attributes of an objectwe have while creating objects. 9
  • 10. example: constructor overloading example: classLanguage{ String name; Language() { System.out.println("Constructor methodcalled."); } Language(String t) { name = t; } public static void main(String[] args) { Language cpp = new Language(); Language java = new Language("Java"); cpp.setName("C++"); java.getName(); cpp.getName(); } void setName(String t) { name = t; } void getName() { System.out.println("Language name: " + name); } } 10
  • 11. Output: Constructor method called. Language name: java Language name:c++ 11
  • 12. 12