Saltar al reproductorSaltar al contenido principal
En este video se explica que es un constructor con ejemplos.
¿Que es un constructor?
Constructores en java

#java #programacion #dev #constructor

Categoría

📚
Aprendizaje
Transcripción
00:00Hello everyone, welcome to this new video.
00:02which will deal with constructor methods
00:06let's get started
00:08which is a constructor method
00:09A constructor method is one that is executed when a method is created.
00:14an object of this class
00:16In this case we have a class called book
00:20which contains three attributes
00:24that those three attributes are two of type string
00:28script and one
00:30of type
00:32integer primitive data
00:34have
00:35as the first builder
00:37a default constructor
00:40This builder
00:41It is used for
00:44initialize the variables
00:45every time
00:48that an instance of this class is created
00:50in this case
00:52the class is called book
00:54so
00:56This method what is done
00:58that once an instance of this class is created
01:02he initializes
01:04the attributes of this class
01:07this
01:10we can see that it assigns it
01:12a stranger
01:14by title and author
01:16which are two of the
01:18two of the attributes
01:20string type
01:21from the book class
01:23and we have
01:24that initializes
01:26the page number
01:29initializes it by assigning it the value of zero
01:32as we can see
01:34Here we have
01:35another builder
01:37parameterized call
01:39which receives
01:41parameters to be able to initialize the object
01:45when creating an instance
01:47of this kind book
01:48now about us
01:50instantiate the book class
01:52to create an object
01:54then
01:57This builder
01:59is going to ask
02:00three parameters
02:01two types of script
02:04and one
02:07of integer primitive data
02:09what is the page number
02:11what does that mean
02:13that every time you want to create an instance
02:16from the book class
02:18the builder
02:20will tell you what you need
02:24the three object parameters
02:28which are the three instances
02:30from the book class
02:32so
02:33so that
02:35the reserved word is used
02:38dis
02:38Well
02:39this word dis
02:41is used to refer to
02:43in the current instance
02:44of
02:45the object
02:46what does it mean
02:47Here we have
02:50two variables
02:51calls
02:52qualification
02:53TRUE
02:54so
02:56if one removes
02:56This dis
02:58it would look like this
02:59qualification
03:00is equal to title
03:01I mean
03:02what is
03:03in the variable
03:05qualification
03:05will be assigned to you
03:07to the other variable
03:08qualification
03:09but
03:10so
03:11as
03:11Java
03:12I mean
03:12this
03:14difference
03:15to
03:16this
03:17where to assign it
03:18that variable
03:18because the two
03:19they are called
03:20equal
03:21so
03:22which
03:22makes the word
03:24dis
03:24dis
03:26in Spanish
03:27wants to refer
03:28like what
03:29this
03:29this case
03:31means
03:31that
03:32this
03:33qualification
03:34I mean
03:34This variable
03:35will save
03:36what is going to be received
03:38by
03:38parameter
03:40this
03:41qualification
03:43will be saved
03:45in
03:45will be saved
03:51in it
03:51attribute
03:52qualification
03:53of the class
03:54for that
03:56is used
03:57dis
03:58and how
04:00can see
04:01here
04:01have
04:03a
04:05a method
04:07called
04:08display data
04:09that does not receive
04:11none
04:11parameter
04:11this
04:13This method
04:15is of type
04:16public
04:17and
04:19returns
04:19void
04:20of type
04:21return
04:22void
04:22that
04:23void
04:23means
04:24that
04:24does not return
04:26nothing
04:26I mean
04:27void
04:28in Spanish
04:28means
04:29empty
04:30so
04:31This method
04:32has
04:33a
04:33system
04:34spot
04:34spot
04:35print
04:35this
04:37this
04:37I mean
04:38will show
04:39by
04:39console
04:40is going to print
04:41by console
04:42what this
04:44inside
04:44of these
04:44parenthesis
04:45and in this
04:46case
04:46will show
04:47qualification
04:48concatenated
04:50dis
04:51spot
04:51qualification
04:52what does he want
04:52say
04:53when
04:54this
04:54dis
04:54spot
04:54qualification
04:55will show
04:56is what
04:57contains
04:58the
05:00variable
05:01qualification
05:02but
05:03of the
05:04of the
05:06attribute
05:06of the
05:06class
05:07and by
05:09here
05:09have
05:10other
05:11other
05:13method
05:13that returns
05:15of type
05:16public
05:17that returns
05:17a
05:17string
05:18what are you doing
05:20this
05:20method
05:21well
05:22this
05:22method
05:23returns
05:24returns
05:25a
05:25string
05:26chain
05:27which
05:29us
05:29indicates
05:30he
05:31state
05:31of the
05:32object
05:32in that
05:33instant
05:34to the
05:35call
05:36to this
05:37method
05:38also
05:40have
05:41a
05:41account
05:42a
05:43class
05:43call
05:44account
05:44banking
05:45where
05:46have
05:46in this
05:47case
05:48three
05:48guys
05:49of
05:49builders
05:50and to this
05:52he is
05:52we call
05:53he is
05:54calls
05:54overload
05:56of
05:57builders
05:57what does he want
05:58say this
05:59what are they
06:00several
06:00builders
06:01with the same
06:02name
06:03but
06:04with
06:04different
06:05parameters
06:05with
06:07different
06:07parameters
06:09as
06:12they can
06:13see
06:13this
06:13have
06:14a
06:15method
06:15default
06:16have
06:17a
06:18method
06:18that
06:19a
06:22method
06:22parameterized
06:23with
06:25two
06:25parameters
06:25and how
06:27they can
06:27see
06:27have
06:28this
06:29with
06:30three
06:30parameters
06:31as
06:33they can
06:33see
06:33here
06:34this
06:35have
06:35this
06:37line
06:37which
06:38wants
06:38explain
06:39the thing is
06:40this
06:40calling
06:40to the
06:42builder
06:42that
06:44has
06:44nothing else
06:45two
06:45parameters
06:46Well
06:47and also
06:48have
06:49a
06:49method
06:49also
06:50called
06:51you
06:51sprint
06:52here
06:52by
06:55here
06:55can
06:56see
06:56by
07:04here
07:04can
07:04see
07:05a
07:05class
07:06of
07:06student
07:07a
07:09class
07:09student
07:10with
07:11his
07:11variable
07:15have
07:17a
07:17class
07:17call
07:18also
07:18student
07:19and
07:20have
07:21a
07:21class
07:21main
07:22where
07:23come on
07:23approve
07:24and
07:28have
07:29a
07:29class
07:29main
07:29where
07:30this
07:32where
07:33can
07:33see
07:34here
07:34where
07:34we create
07:35a
07:36object
07:36a
07:38object
07:38book
07:38called
07:40lb
07:42where
07:44we passed it on
07:45these
07:45parameters
07:46to the
07:46builder
07:46so that
07:47initialize
07:48the
07:49attributes
07:49of
07:50the
07:50instance
07:51here
07:53also
07:54we create
07:54also
07:55this
07:57other
07:58object
07:58student
07:59and another
08:00object
08:01account
08:01banking
08:02we send you
08:03to
08:05this
08:06to this
08:07instance
08:08nothing else
08:08we send you
08:09three
08:10three
08:12parameters
08:14to this
08:14we do not send him
08:15nothing
08:16that's it
08:18we send you
08:18nothing else
08:19two
08:19what do you want
08:20say
08:21this
08:21Yeah
08:22to
08:23this
08:23Yeah
08:25to this
08:26class
08:26this
08:27Well
08:32this
08:33and once
08:35instantiated
08:36the
08:39classes
08:39once
08:41created
08:41the
08:41objects
08:42can
08:44this
08:46we import
08:47the class
08:48scan
08:48this
08:49class
08:50scan
08:50which
08:51us
08:51allows
08:51is
08:52receive
08:53parameters
08:54by
08:55console
08:56by the
08:57terminal
08:58so
08:59as they can
09:01see
09:01here
09:02can
09:03say
09:03system.2.prey
09:05enter the name
09:06of the student
09:07so
09:09that
09:10which
09:11let's write
09:11by console
09:12with the
09:14method
09:14with the
09:15object
09:16with the
09:17object
09:18created
09:18of
09:19rest.netline
09:21which
09:22we are
09:23indicating
09:24that
09:24we are
09:26expecting
09:27by console
09:28this
09:30we are waiting
09:33by console
09:34a
09:34string
09:35and this
09:36will save it
09:37in a
09:38string
09:38call
09:39name
09:39and so on
09:40successively
09:41after
09:43that
09:44all that
09:44is given
09:45after
09:46to have
09:47written
09:47all the
09:47parameters
09:48is created
09:49a
09:50new
09:50object
09:50student
09:51where
09:52he is
09:53send
09:53by parameter
09:54he
09:55worth
09:56of the
09:58variables
09:58that
09:59we had
09:59created
10:00that
10:00we ask
10:00by console
10:02and
10:04that
10:04once
10:05that is
10:05keep
10:06they are
10:06we send
10:07to the
10:07builder
10:11and
10:11which
10:12he's leaving
10:12to
10:12create
10:13a
10:15object
10:15student
10:16with
10:17the
10:17with
10:19the
10:19data
10:19writings
10:20by
10:20console
10:20and
10:22here
10:22can
10:23print
10:23the
10:23details
10:24of the
10:24objects
10:25with
10:25he
10:26method
10:26screen
10:27so
10:28let's execute
10:29this
10:29to see
10:30here
10:32we put
10:32a
10:32name
10:33and
10:43as
10:43they can
10:44see
10:44us
10:46print
10:46in this
10:48case
10:48he
10:49state
10:49of
10:49this
10:50object
10:50here
10:52in it
10:54case
10:54of
10:55student
10:55as
10:56they can
10:56see
10:56here
10:57No
10:57we had
10:58mandate
10:58none
10:59parameter
11:02this wants
11:03say
11:03that
11:04the
11:04initializes
11:05default
11:06so
11:07to no
11:09initialize
11:10a
11:10screen
11:10that
11:11he
11:14worth
11:15of a
11:15screen
11:15default
11:16is
11:16null
11:17and
11:18of a
11:19whole
11:19is
11:19zero
11:20that's why
11:20the thing is
11:20here
11:21No
11:21sample
11:21he
11:21state
11:22of the
11:24object
11:24but
11:24No
11:25sample
11:25that
11:25say
11:26here
11:27can
11:27see
11:28he
11:28state
11:28of
11:29account
11:29banking
11:30that
11:30was
11:31the
11:32parameters
11:32that he
11:32we send
11:33over here
11:33and
11:34he
11:35of
11:35student
11:35that
11:35were
11:36the
11:36that
11:37you
11:37we send
11:37by
11:38console
11:39and
11:41So
11:41ends
11:42this
11:42video
Sé la primera persona en añadir un comentario
Añade tu comentario

Recomendada

7:02
Próximamente