The string class is the final class, why the string class can be instantiated and can be assigned

Updated on technology 2024-02-10
9 answers
  1. Anonymous users2024-02-06

    Of course, you can instantiate.

    The final class cannot be inherited by other classes.

    Yes, it can be assigned, but it can only be assigned once. string is a constant.

    string a = "aaa";

    a = "bbb"

    The a variable is not a reassignment, it just points to another string.

    Strings"aaa"、"bbb"It can't be more deserved.

  2. Anonymous users2024-02-05

    When final modifies a class, it means that the class cannot be inherited, and only abstract classes cannot be instantiated.

    final modifier means that the method cannot be overwritten.

    When final modifies a variable, the value of the variable cannot be changed.

    When you decorate an object, it means that the reference to the object cannot be changed, but the properties of the object can still be changed.

  3. Anonymous users2024-02-04

    It can be instantiated, but it can't be inherited.

  4. Anonymous users2024-02-03

    The final class can be instantiated and assigned. But the problem is that you can't go and change it straight. Like what.

    Or are you sure you really understand the meaning of final?

  5. Anonymous users2024-02-02

    The final class can be instantiated, and defining a class as final simply means that the class cannot be inherited. For example, if you want to write a class that inherits from a string (or your own definition of a final class), you won't do that. The final variable, as they say, can only be assigned once, and when trying to change it, an error will be reported.

  6. Anonymous users2024-02-01

    The final class can be instantiated, but it can't change its value after instantiating the assignment, and if it can't be assigned, then it doesn't have any meaning.

  7. Anonymous users2024-01-31

    Not necessarily. final is used to declare properties, methods, and classes, respectively indicating that a property must be initialized and immutable once it is allocated memory space, that a method must be implemented once it is defined and cannot be overridden in a subclass, and that a class, once defined, cannot be defined as an abstract class or interface because it cannot be inherited.

    The focus is on once memory space is allocated.

    You can: public class test{public final int a = 1; Initialize at declaration time.

    public test(){

    Alternatively: public class test{public final int a;

    public test(){

    a = 1;Initialize in the constructor.

    Why can it be initialized in the constructor? Because when the class is loaded into memory, this property does not allocate memory space to it, but only defines a variable, and only when the class is instantiated, this property is allocated memory space, and the constructor is executed at the same time when instantiated, so the property is initialized, which also meets the condition that it needs to be initialized when it is allocated memory space, and will not be changed in the future.

  8. Anonymous users2024-01-30

    The string class is the final class and therefore cannot be inherited, which means that the string content of the string cannot be modified. There are two ways to instantiate string:

    1) Direct assignment (e.g., string str =.)"hello";is directly assigned to instantiate).

    2) Use the new call constructor to complete instantiation;

    It should be noted that the content of a string object cannot be modified, but that does not mean that its reference cannot be changed.

  9. Anonymous users2024-01-29

    That's right, because the string class modifier is final

Related questions
10 answers2024-02-10

First of all, a Class C has 254 addresses but there is always one as a gateway route, so there can be a maximum of 253 hosts. Then these hosts are public IP addresses. It can be done by setting up a LAN and using one IP. >>>More

9 answers2024-02-10

Class C fires are gas fires. Such as fires caused by gas, natural gas, methane, ethane, propane, hydrogen, etc. >>>More

9 answers2024-02-10

A low-purine diet is one that reduces the synthesis of purines. Purines are constituent substances of nucleoproteins, which are the first of uric acid. Normally, purines are oxidized and metabolized by the liver before they become uric acid, which is then excreted by the kidneys and intestines. >>>More

14 answers2024-02-10

Know is a search-based interactive quiz sharing platform that was released on June 21, 2005 and became official on November 8, 2005. Know has been exploring international development, released on March 31, 2012 Know Taiwan Edition. >>>More

30 answers2024-02-10

The Q version of the style RPG turn-based online game is currently the most popular in China, and its popularity is far ahead of the second-ranked WOW, that is, World of Warcraft. At present, there is only one way to charge the point card, 1 hour 4 o'clock, 150 points 15 yuan, itself is not expensive, but this game generally has to be double-opened 3 or even more open, so a sum up, its point card is more expensive. The fastest way to become stronger in the game is to smash RMB, so this is another very expensive game, and countless people have spent money on it. >>>More