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
Related
This question already has answers here:
What is the use of an empty abstract class?
(3 answers)
Closed 5 years ago.
Yesterday, I had an interviewing with a company.
They ask me "Why do we need an empty class in Java?"
I never use an empty class so I have no idea about the purpose of this.
Anyone help?
Thank you so much.
No, we don't need an empty class in Java. We can create one but there is literally no benefit of having that empty class.
This question already has answers here:
Casting variables in Java
(5 answers)
Downcasting in Java
(12 answers)
Closed 6 years ago.
As the title,
Assume that there's a KiahApplication class that extends Application,
I've seen the code below:
KiahApplication Kapp=(KiahApplication)getApplication();
But isn't it incorrect to cast a superclass to its subclass?
Thank you so much for helping!
No, it's not illegal and sometimes is necessary. The important thing is to be sure that the object is an instance of the subclass. You can do this by testing it in code or by catching the potential ClassCastException. In the example you give, if you are absolutely sure that the Application object is of the right type then you could leave as is.
This question already has answers here:
Possible to use two java classes with same name and same package?
(8 answers)
Closed 7 years ago.
I need to use two same named class in the same package.can i do it? like
package MyPackage;
class pkg{
}
class pkg{
}
Is it correct?
You should learn to try these things yourself, or read the language specification.
The short answer is no, you can't do that.
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.
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.