Facebook – https://www.facebook.com/TheNewBoston-464114846956315/ GitHub – https://github.com/buckyroberts Google+ …
source
Please support this website by disabling your AdBlocker
Please contact with the webmaster of the website if you think something is wrong.
I understand that what he's saying is incorrect, but how come the output displays what he says in the video?
this keyword is used for calling data members not local variable…..u figured it out little wrong…..but u r doing a great job…
Try running this.You will understand by yourself. Look how the value is changing.public class hachuwa {
//The variableprivate String abc = "instance variable";
public void main(string args[]){//Initializing your local variable
String abc = " ";//Study what happens when you remove
-this-.this.abc = "Parameter";
System.out.print("Local ="abc);
}
void def(){
System.out.print("Instance "+abc);
}
}
u are explaining exactly the opposite….. if we use this keyword , it will refer to instance variable….. and if we dont use this variable it will point to local variable ( arguments of functions)
Love the comment section! Least toxic on youtube and most helpful!!!
"this" explanation is wrong!!! when we use this.hour it will use private member hour that is this class hour.
Exact opposite of what the actual purpose of "this" is.
i am crying with "this" tone :'D
You're such a funny guy!!!
Love your vids 😀
What circumstances would the 'this' method even be needed?
Bucky was drunk when he did this!
what if i didnt use private or public in instance variable?
[ASK] this.hour should belong to the object's properties, right?
“`
private int hour, minute, second;
public void setTime(int hour, int m, int s){
this.hour = (hour>0 && hour <=24)? hour : 0;
minute = (m>0 && m <=60)? m : 0;
second = (s>0 && s <=60)? s : 0;
}
“`
this.hour refers to the global variables. You are going to give some poor soul a headache trying to replicate your explanation into thier prgm.
I'd like to point out that public variables can be accessed from a static context.
I.e. from your apples class you can access the tuna variable:
public int hour;
using the (tuna Object).hour
However, this is very bad practice. you always want to privatize all variables habitually if they need to be accessed from a static context you should implement setter and getter functions.
This is because someone can set class specific variables outside of the constraints intended. They could for instances set the hour by calling
(tuna object).hour = 0;
and if for some reason you were dividing hours they could break your program by forcing a division by zero.
The best way to cover your code is to not expose it, Privatize EVERYTHING.
😛
Yeah this is wrong…
I always call my global varibles of my classes
g_width, g_height, g_name so i know they are the global vars
You could also write the first letter with a capital, which you never really so normal with camel case.
You could write in full caps but that is usually used for constants (finals)
Is it correct now or not, anyone (or Bucky)?
i can't understand from where the scope is local and when it become to globel can any one help me?
ATTENTION!!! when we use 'this. ' . It will generally refers to data member of class. with using ' this.' if any change is made this will reflect to data member of class not local variable to method(function).
but what if I am using same hour minute and second more than twice in a program.and "this" has other things too than this name management thing and I don't really understand that so please explain.
this explanation is for someone who already know how "this" works
dude…bucky….come on!
Glad I understood this properly before watching this video, because this is wrong.
private final int hour =1;
private final int minute =2;
private final int second = 3;
You don''t Write final
that is not what "this" is
Yeah you can tell that Bucky likes c++ much more
Did his example work because he reassigned hours, minute, and second? If he just used this.hour, this.minute, this.second the out put would be 1, 2, 3?
My little ex went away XD
I don't get it, how is he wrong?
What he's explaining also shows up in the program. Using .this made sure to use the variables in the setTime. That's what you see in the program as well right?? 🙂
hi!! thank you so much your tutorials are great and intelligible
"this ones," You have got me ROLLING! it is late and i've been watching java videos for hours, and your humour is killing me, haha!
Excuse me Bucky, wrong explanation as "this" refer to the variable of the current class, not the argument. 🙂
Since bucky's explanation of the keyword "this" is wrong, I made a simple program to make things more clear because I was really confused at first:
public class test{
int a=5;
void print(int a){
System.out.println(a);
System.out.println(this.a);
}
public static void main(String args[]){
test object=new test();
object.print(3);
}
}
The output of this program would be:
3
5
So inside the method print, a refers to the local variable and this.a refers to the instance variable.
It uses setTine(int hour, int minute… by default. If you have some values that have the same name outside the method (private int hour; ) you need to use "this." to access them. If you want to use values that are even further out from the method you have to use "this.this." Fuck you Bucky! This is a troll tutorial xD
bucky ! u just unexpectedly disappointed me for the very first time :O
When creating a new method, when do you use public String args.. and when do you use public void args…and why? For example: public String toMilitary(){} or public void toMilitary(){} If anyone could help me out with this that would be much appreciated.
Be careful, although the overall quality is very good. This video contains wrong information about 'this'.
I think it is better to use setTime() instead of setTime(x,y,z), the input variable seems useless and easily misleading others
thanks for the videos