In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Today, I will talk to you about the hot written test questions about Java, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
a. Two public-decorated classes can exist in a file at the same time
b. Constructors can be overridden (override)
c. Subclasses cannot access properties that are not public and protected decorated by the parent class
D.final-decorated classes can be inherited
Answer: C
There can be at most one public class in a Java source file. When there is a public class, the source file name must match it, otherwise it cannot be compiled. If there is no public class in the source file, there is no consistency requirement between the file name and the class. As for main (), you don't have to put it in the public class to run the program.
Overriding is when the subclass inherits the parent class and modifies the method of the parent class. The method name, parameters, and return value must be the same. Methods marked as final cannot be overridden. If you cannot inherit a method, you cannot override it.
Extension: the difference between rewriting override and reloading overload
Method overloading of java
It is possible to create multiple methods in a class that have the same name but different parameters and different definitions. When a method is called, the specific method is determined by the number and type of parameters passed to them, and the return type can be the same or different, which is also an object-oriented polymorphism.
Java's method overrides
The polymorphism between the parent class and the subclass redefines the function of the parent class. If a method is defined in a subclass with the same name and parameters as its parent class, we say that the method is Overriding. In Java, subclasses can inherit methods in the parent class without having to rewrite the same methods. But sometimes the subclass does not want to inherit the method of the parent class intact, but wants to make some changes, which requires the rewriting of the method. Method rewriting is also called method override.
If a method in a subclass has the same method name, return type, and parameter table as a method in the parent class, the new method will overwrite the original method. For the original methods in the parent class, you can use the super keyword, which references the parent class of the current class.
The access modification permission of a subclass function cannot be less than that of the parent class.
Overridden methods can only exist in inherited relationships, and override methods that are not private to the parent class.
2 int for (YBG 0) & & (x)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.