How would you characterize the term "this" in java? [duplicate] - java

This question already has answers here:
Is there a name for "this" in Java?
(12 answers)
Closed 8 years ago.
Simple question, I know what this does in Java but is this considered an instance variable belonging to the class?

this is not an instance variable belonging to the class. this is a reference to an instance of the current class.

Related

Can the constructor of a child class update the values of variables in the parent class [duplicate]

This question already has answers here:
Java Base Class Reference Variable
(3 answers)
Instantiating base class using derived class?
(2 answers)
Polymorphism and Constructors
(2 answers)
Why does Java base class constructor call derived class' methods? [duplicate]
(2 answers)
Which OO concept is "Base b = new Derived()" an example of?
(10 answers)
Closed last month.
question problem
In the question above var 1 is of type A but is calling the constructor of class B. So will passing the parameter 4 to the constructor update the "value" variable to 4 or will it remain 3.
I was expecting the answer of the final question to be 11 but it was actually 10.
No. If the variable is calling a constructor from a different class, it will not update anything in the A class at all even though the two classes use a constructor with the same name. The two constructors go to two different locations in memory.

Checking if an unknown class given by getClass() is a certain class [duplicate]

This question already has answers here:
Check if an object belongs to a class in Java [duplicate]
(6 answers)
What is the 'instanceof' operator used for in Java?
(18 answers)
Closed 2 years ago.
I have a type of Object variable called obj (Object obj). I'm using obj.getClass() and I want to check if the returned class is actually a certain class, in my case a class named Student. How do I do that?
I tried obj.getClass().isInstance(Student) but it tells me that Student cannot be resolved to a variable. Also yes I've done my research and have found similar questions on SO but for some reason nothing I've done works.
You can use ‘Student.class.isAssignableFrom(obj.getClass())‘ or if you have the instance of the object just ‘obj instanceof Student‘.

what are the project related scenarios in which we have to make a class Final in java? [duplicate]

This question already has answers here:
Good reasons to prohibit inheritance in Java?
(11 answers)
What is the point of "final class" in Java?
(24 answers)
Closed 3 years ago.
What will be the scenario in a real project to specially use the Final Class?
P.S: Final Class is for preventing the class from sub-classing that class.

How to make java String class mutable? [duplicate]

This question already has answers here:
Create a mutable java.lang.String
(6 answers)
Closed 5 years ago.
I want to make String class mutable, simplest way to do this is make inner char array is public. How can i achive it?
I'm pretty new to this so sorry if this is wrong.
Wouldn't it be possible to inherit from the String class then override the required method?
Adam

What does "SomeClass.this" mean in java? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is the difference between Class.this and this in Java
I know what this means in Java, but sometimes I see something like SomeClass.this, what does it mean? does it refer to a static class filed? Could you please explain with an example?
Thanks.
It is a way code in a method of your inner class can refer to the encompassing outer class instance.

Categories

Resources