Loading topic
new, use public and private, and read basic inheritance code. It covers what a static field is, where its value lives, how to read and write it, and the mistakes that 6 min readpublic and private. The previous chapter covered static fields. This one covers static methods: how to declare and call them, what happens when you call them, and how to decide whether a6 min readnew, use public and private, and override methods in a subclass. It explains the rules for what code in a static context can reach, why those rules exist, and how to work around them correctl6 min readpublic and private, and you have seen static fields shared by all instances. Here you will learn how static final creates constants, what the compiler does with them, and where they stop being constant.6 min readstatic means for a field and for a method, and you have seen basic inheritance. The chapter covers when Java runs static initialization code, in what order, and what goes wrong when tha6 min readstatic means for a method, and you know a static method has no this. It builds on the static context rules from earlier chapters.6 min readprivate and final work. Earlier chapters covered the rules for static context. This chapter looks at one design built from those rules: a class6 min readMath.max(3, 7). It also assumes you know how import statements and packages work. Here you learn how a static import removes the class-name prefix, how Java resolves the short names 6 min readextends, override an instance method with @Override, and read a method call such as animal.name(). It also assumes you know what static means for a field or method. The chapter explains why a subclass can redeclare a static method but5 min readstatic modifier. This chapter assumes you can write classes with fields, constructors and methods, and that you know access modifiers and the difference between static and instance members from the earlier chapters. You should6 min readstatic final constants work, and how to start a Thread with a Runnable. It covers why mutable static fields cause concurrency bugs, how to fix them, and which static patterns are already safe.5 min readstatic final constants. It also assumes you know the static context rules and method hiding from earlier chapters, plus the basics of threads. The goal here is to turn those mechanics into design decisions.6 min read