Saltar al reproductor
Saltar al contenido principal
Buscar
Iniciar sesión
Ver en pantalla completa
Me gusta
Añadir marcador
Compartir
Más
Añadir a la lista de reproducción
Denunciar
Modificador static en java || Taller 3
Ronald
Seguir
hace 5 semanas
En este video se explica que es static.
Categoría
📚
Aprendizaje
Transcripción
Mostrar la transcripción completa del vídeo
00:00
Hello, welcome to a new video about the stati modifier in Java.
00:08
Well, in Java the stati modifier is used to define members of a class, attributes or methods,
00:17
that belong to the class itself rather than the object instance.
00:22
So what does this mean? That when you create an instance of a class,
00:33
that instance, the static attribute or method will belong to the class, not the instance.
00:44
So, let's look at it with some examples I have back.
00:49
Now, we have a class called car, which has public access modifier with two attributes,
01:03
two attributes called brand and another model,
01:10
which we have an integer type stati variable called car counter.
01:20
And we have the attribute parameterized with two parameters, brand and model,
01:29
which is initialized.
01:30
And here we see something that is the car counter.
01:38
What does this do?
01:39
That every time a car object is created, a car instance,
01:46
What this will do is increase the car counter variable by one.
01:54
What's happening?
01:55
That every time a car object is created, what it will do is that this variable,
02:02
As it is of all classes, it will show the number of cars that are being created.
02:11
So here we're going to do a sample, here we're going to create, here we're going to instance,
02:24
let's create a car object, then, car here ready.
02:31
So, once that object is created, the counter will increase by one,
02:41
This is going to increase by one, because as we can see, we have here the instance where that object was created.
02:52
And we can see that every time that car class is instantiated, the car counter is incremented.
03:07
So what's going on here?
03:12
This method, we have a static method that does not return anything.
03:16
What does a static method mean?
03:18
A static method, also, is one that is of the class, is of the class, but is not instantiated.
03:30
So you don't need to create one, create an instance where it is,
03:37
an instance of a class where that method is located so that it can be accessed.
03:42
But we can access, access that method directly.
03:48
There you can access it without having to create an instance.
03:53
And here mark one, because we created a single object.
04:00
But if we create multiple objects, here I show you.
04:03
The result would be 3.
04:15
As we can see, correct.
04:17
For that,
04:21
Here we have,
04:22
Here we have another one,
04:26
another example of static methods.
04:28
Here we have,
04:30
Here we have this class called mathematics,
04:34
which contains the operations,
04:37
four basic operations,
04:39
addition, subtraction, multiplication and division.
04:42
What this static method does,
04:45
which returns an integer.
04:48
And, by parameter,
04:51
It needs two parameters,
04:53
two integers.
04:54
And this is going to return depending on what the method is.
05:00
If it is the sum,
05:01
returns the sum of these two parameters that we send to it.
05:05
So,
05:06
as they are static,
05:08
it is necessary to create one,
05:11
create an object of that class to be able to access its methods.
05:15
But,
05:17
that already being within the same package,
05:19
we can access it
05:21
directly.
05:23
So,
05:24
we make a,
05:27
here we will try
05:31
how the sum works.
05:36
And we access it directly.
05:37
And when executing it,
05:39
we see that the sum is 5
05:43
and everything works correctly.
05:46
So
05:51
and
05:51
and
05:52
and
Sé la primera persona en añadir un comentario
Añade tu comentario
Recomendada
5:10
|
Próximamente
Modificador de Acceso protected en Java || Taller 6
Ronald
hace 5 semanas
5:18
Insertar un carácter en una posición específica de una cadena en Java
BetoDev
hace 2 años
1:31
Calcular el perímetro de un hexágono en Java
BetoDev
hace 2 años
2:34
Calcular el perímetro de un triángulo en Java
BetoDev
hace 2 años
2:28
Calcular el volumen de un cilindro en Java
BetoDev
hace 2 años
4:02
Sacar el promedio de tres notas y mostrar un mensaje si aprobó o réprobo en Java
BetoDev
hace 2 años
4:34
Calcular el área de un triángulo conociendo sus tres lados en Java
BetoDev
hace 2 años
3:32
Generar serie: 1,4,9,16,25,36,... en Java
BetoDev
hace 2 años
7:04
Sobre escritura de Métodos en Java || Taller 10
Ronald
hace 5 semanas
3:44
Uso de super en Java || Taller 9
Ronald
hace 5 semanas
5:47
Herencia Simple en Java || Taller 8
Ronald
hace 5 semanas
8:10
Modificador de Acceso public en Java || Taller 7
Ronald
hace 5 semanas
5:29
Modificador de paquete (default) en java || Taller 5
Ronald
hace 5 semanas
4:18
Modificador de acceso private en java || Taller 4
Ronald
hace 5 semanas
7:02
Uso de this en java || Taller 2
Ronald
hace 5 semanas
11:44
Constructores en java || Taller 1
Ronald
hace 5 semanas
0:51
Former Aide Claims She Was Asked to Make a ‘Hit List’ For Trump
Veuer
hace 2 años
1:08
Musk’s X Is ‘the Platform With the Largest Ratio of Misinformation or Disinformation’ Amongst All Social Media Platforms
Veuer
hace 2 años
4:50
59 companies that are changing the world: From Tesla to Chobani
Fortune
hace 2 años
0:46
3 Things to Know About Coco Gauff's Parents
People
hace 2 años
0:35
8 Things to Do in the Morning to Improve Productivity
Martha Stewart Living
hace 2 años
2:11
Why You Should Remember Aretha Franklin
Goalcast
hace 2 años
1:18
USC vs. Colorado: Can Caleb Williams Earn a New Heisman Moment?
SportsGrid
hace 2 años
1:04
Vic Mensa Reveals Celebrity Crush, Biggest Dating Pet Peeve & More on Speed Dating | Billboard News
Billboard
hace 2 años
1:09
Hollywood Writers Reach ‘Tentative Agreement’ With Studios After 146 Day Strike
Veuer
hace 2 años
Sé la primera persona en añadir un comentario