[{"data":1,"prerenderedAt":2327},["ShallowReactive",2],{"blog-\u002Fblog\u002Fjava-keywords-modifiers-static-final":3},{"id":4,"title":5,"body":6,"description":2313,"difficulty":2314,"extension":2315,"framework":2316,"frameworkSlug":172,"meta":2317,"navigation":764,"order":222,"path":2318,"qaPath":2319,"seo":2320,"stem":2321,"subtopic":2322,"topic":2323,"topicSlug":2324,"updated":2325,"__hash__":2326},"blog\u002Fblog\u002Fjava-keywords-modifiers-static-final.md","Java Keywords & Modifiers — Access, static, final & abstract Explained",{"type":7,"value":8,"toc":2296},"minimark",[9,14,60,64,75,167,265,298,302,320,462,478,482,496,643,650,654,689,804,833,837,851,905,921,925,952,1056,1074,1078,1093,1217,1227,1231,1244,1324,1367,1387,1391,1432,1562,1581,1585,1600,1706,1730,1734,1761,1885,1917,1921,1935,2043,2059,2063,2089,2170,2209,2213,2292],[10,11,13],"h2",{"id":12},"keywords-and-modifiers-are-the-dialect-of-java","Keywords and modifiers are the dialect of Java",[15,16,17,18,22,23,26,27,31,32,35,36,39,40,43,44,48,49,52,53,39,56,59],"p",{},"Most of Java's grammar is built from a small vocabulary of ",[19,20,21],"strong",{},"keywords",", and a handful of\nthem — the ",[19,24,25],{},"modifiers"," — decide ",[28,29,30],"em",{},"who can see"," a member, ",[28,33,34],{},"how many copies"," exist, ",[28,37,38],{},"whether\nit can change",", and ",[28,41,42],{},"how it behaves across threads",". Interviewers love this material\nbecause each keyword carries a precise, often surprising rule: ",[45,46,47],"code",{},"final"," doesn't make objects\nimmutable, ",[45,50,51],{},"static"," methods can't touch ",[45,54,55],{},"this",[45,57,58],{},"var"," isn't actually a keyword. This\nguide threads them into a single story so the rules stick instead of floating as\nflashcards.",[10,61,63],{"id":62},"the-four-access-modifiers","The four access modifiers",[15,65,66,67,70,71,74],{},"Access modifiers control ",[19,68,69],{},"visibility"," — who is allowed to reference a class, field,\nmethod, or constructor. Java has four levels, and the fourth is the one you get by writing\n",[28,72,73],{},"nothing",":",[76,77,78,101],"table",{},[79,80,81],"thead",{},[82,83,84,88,92,95,98],"tr",{},[85,86,87],"th",{},"Modifier",[85,89,91],{"align":90},"center","Same class",[85,93,94],{"align":90},"Same package",[85,96,97],{"align":90},"Subclass (other pkg)",[85,99,100],{"align":90},"Everywhere",[102,103,104,122,137,152],"tbody",{},[82,105,106,112,115,118,120],{},[107,108,109],"td",{},[45,110,111],{},"private",[107,113,114],{"align":90},"yes",[107,116,117],{"align":90},"no",[107,119,117],{"align":90},[107,121,117],{"align":90},[82,123,124,129,131,133,135],{},[107,125,126],{},[28,127,128],{},"(default)",[107,130,114],{"align":90},[107,132,114],{"align":90},[107,134,117],{"align":90},[107,136,117],{"align":90},[82,138,139,144,146,148,150],{},[107,140,141],{},[45,142,143],{},"protected",[107,145,114],{"align":90},[107,147,114],{"align":90},[107,149,114],{"align":90},[107,151,117],{"align":90},[82,153,154,159,161,163,165],{},[107,155,156],{},[45,157,158],{},"public",[107,160,114],{"align":90},[107,162,114],{"align":90},[107,164,114],{"align":90},[107,166,114],{"align":90},[168,169,174],"pre",{"className":170,"code":171,"language":172,"meta":173,"style":173},"language-java shiki shiki-themes github-light github-dark","public class Account {\n  private double balance;   \u002F\u002F only this class can see it\n  String owner;             \u002F\u002F package-private — no keyword at all\n  protected int id;         \u002F\u002F package + any subclass\n  public String getOwner() { return owner; }  \u002F\u002F anyone\n}\n","java","",[45,175,176,195,211,220,235,259],{"__ignoreMap":173},[177,178,181,184,187,191],"span",{"class":179,"line":180},"line",1,[177,182,158],{"class":183},"szBVR",[177,185,186],{"class":183}," class",[177,188,190],{"class":189},"sScJk"," Account",[177,192,194],{"class":193},"sVt8B"," {\n",[177,196,198,201,204,207],{"class":179,"line":197},2,[177,199,200],{"class":183},"  private",[177,202,203],{"class":183}," double",[177,205,206],{"class":193}," balance;   ",[177,208,210],{"class":209},"sJ8bj","\u002F\u002F only this class can see it\n",[177,212,214,217],{"class":179,"line":213},3,[177,215,216],{"class":193},"  String owner;             ",[177,218,219],{"class":209},"\u002F\u002F package-private — no keyword at all\n",[177,221,223,226,229,232],{"class":179,"line":222},4,[177,224,225],{"class":183},"  protected",[177,227,228],{"class":183}," int",[177,230,231],{"class":193}," id;         ",[177,233,234],{"class":209},"\u002F\u002F package + any subclass\n",[177,236,238,241,244,247,250,253,256],{"class":179,"line":237},5,[177,239,240],{"class":183},"  public",[177,242,243],{"class":193}," String ",[177,245,246],{"class":189},"getOwner",[177,248,249],{"class":193},"() { ",[177,251,252],{"class":183},"return",[177,254,255],{"class":193}," owner; }  ",[177,257,258],{"class":209},"\u002F\u002F anyone\n",[177,260,262],{"class":179,"line":261},6,[177,263,264],{"class":193},"}\n",[15,266,267,268,271,272,275,276,278,279,281,282,284,285,287,288,291,292,294,295,297],{},"The no-keyword level is called ",[19,269,270],{},"package-private"," (or just \"default\"); it is ",[28,273,274],{},"not"," a\nkeyword you can type. The key distinction between ",[45,277,111],{}," and ",[45,280,143],{}," is the\ninheritance gap: ",[45,283,111],{}," is locked to its own class — even subclasses can't see it —\nwhile ",[45,286,143],{}," reaches subclasses ",[28,289,290],{},"including ones in a different package",", the one case\npackage-private doesn't cover. The guiding principle is to make everything as ",[19,293,111],{},"\nas possible and widen only when a real need appears: ",[45,296,143],{}," signals \"this is part of\nthe inheritance contract,\" not just \"I needed to reach it from over there.\"",[10,299,301],{"id":300},"static-bound-to-the-class-not-the-object","static: bound to the class, not the object",[15,303,304,305,307,308,311,312,315,316,319],{},"The ",[45,306,51],{}," keyword binds a member to the ",[19,309,310],{},"class itself"," rather than to any instance.\nThere is exactly ",[19,313,314],{},"one shared copy",", reachable through the class name with no ",[45,317,318],{},"new","\nrequired. It applies to fields, methods, nested classes, and initializer blocks.",[168,321,323],{"className":170,"code":322,"language":172,"meta":173,"style":173},"class Counter {\n  static int total;          \u002F\u002F ONE copy shared by every Counter\n  int id;                    \u002F\u002F one per instance\n  Counter() { id = ++total; }\n  static int square(int n) { return n * n; }  \u002F\u002F call without an object\n}\nCounter.square(5);           \u002F\u002F 25 — no instance needed\nnew Counter();               \u002F\u002F id=1, total=1\nnew Counter();               \u002F\u002F id=2, total=2  (total is shared)\n",[45,324,325,335,348,359,376,412,416,437,450],{"__ignoreMap":173},[177,326,327,330,333],{"class":179,"line":180},[177,328,329],{"class":183},"class",[177,331,332],{"class":189}," Counter",[177,334,194],{"class":193},[177,336,337,340,342,345],{"class":179,"line":197},[177,338,339],{"class":183},"  static",[177,341,228],{"class":183},[177,343,344],{"class":193}," total;          ",[177,346,347],{"class":209},"\u002F\u002F ONE copy shared by every Counter\n",[177,349,350,353,356],{"class":179,"line":213},[177,351,352],{"class":183},"  int",[177,354,355],{"class":193}," id;                    ",[177,357,358],{"class":209},"\u002F\u002F one per instance\n",[177,360,361,364,367,370,373],{"class":179,"line":222},[177,362,363],{"class":189},"  Counter",[177,365,366],{"class":193},"() { id ",[177,368,369],{"class":183},"=",[177,371,372],{"class":183}," ++",[177,374,375],{"class":193},"total; }\n",[177,377,378,380,382,385,388,391,395,398,400,403,406,409],{"class":179,"line":237},[177,379,339],{"class":183},[177,381,228],{"class":183},[177,383,384],{"class":189}," square",[177,386,387],{"class":193},"(",[177,389,390],{"class":183},"int",[177,392,394],{"class":393},"s4XuR"," n",[177,396,397],{"class":193},") { ",[177,399,252],{"class":183},[177,401,402],{"class":193}," n ",[177,404,405],{"class":183},"*",[177,407,408],{"class":193}," n; }  ",[177,410,411],{"class":209},"\u002F\u002F call without an object\n",[177,413,414],{"class":179,"line":261},[177,415,264],{"class":193},[177,417,419,422,425,427,431,434],{"class":179,"line":418},7,[177,420,421],{"class":193},"Counter.",[177,423,424],{"class":189},"square",[177,426,387],{"class":193},[177,428,430],{"class":429},"sj4cs","5",[177,432,433],{"class":193},");           ",[177,435,436],{"class":209},"\u002F\u002F 25 — no instance needed\n",[177,438,440,442,444,447],{"class":179,"line":439},8,[177,441,318],{"class":183},[177,443,332],{"class":189},[177,445,446],{"class":193},"();               ",[177,448,449],{"class":209},"\u002F\u002F id=1, total=1\n",[177,451,453,455,457,459],{"class":179,"line":452},9,[177,454,318],{"class":183},[177,456,332],{"class":189},[177,458,446],{"class":193},[177,460,461],{"class":209},"\u002F\u002F id=2, total=2  (total is shared)\n",[15,463,464,465,467,468,471,472,477],{},"A ",[19,466,51],{}," member belongs to the class for the program's lifetime; an ",[19,469,470],{},"instance","\nmember is born with each object. The crucial constraint: a static method ",[19,473,474,475],{},"can't use\n",[45,476,55],{}," or read instance fields directly, because no particular object is in play — static\ncode can only see static state, while instance code sees both. That shared-by-everyone\nnature also makes mutable static state a classic source of threading bugs and memory leaks,\nso reserve it for genuinely global, ideally immutable, values.",[10,479,481],{"id":480},"static-nested-classes-vs-inner-classes","static nested classes vs inner classes",[15,483,484,485,487,488,491,492,495],{},"Marking a nested class ",[45,486,51],{}," changes its relationship to the enclosing object. A\n",[19,489,490],{},"static nested class"," holds no reference to an outer instance and can be created\nstandalone; a non-static ",[19,493,494],{},"inner class"," is tied to an outer instance and can read its\nmembers.",[168,497,499],{"className":170,"code":498,"language":172,"meta":173,"style":173},"class Outer {\n  int x = 10;\n  static class Nested { int sum(int a) { return a + 5; } }  \u002F\u002F no Outer link\n  class Inner { int read() { return x; } }                  \u002F\u002F uses Outer's x\n}\nOuter.Nested n = new Outer.Nested();      \u002F\u002F no Outer instance required\nOuter.Inner i = new Outer().new Inner();  \u002F\u002F needs an enclosing Outer\n",[45,500,501,510,525,568,593,597,619],{"__ignoreMap":173},[177,502,503,505,508],{"class":179,"line":180},[177,504,329],{"class":183},[177,506,507],{"class":189}," Outer",[177,509,194],{"class":193},[177,511,512,514,517,519,522],{"class":179,"line":197},[177,513,352],{"class":183},[177,515,516],{"class":193}," x ",[177,518,369],{"class":183},[177,520,521],{"class":429}," 10",[177,523,524],{"class":193},";\n",[177,526,527,529,531,534,537,539,542,544,546,549,551,553,556,559,562,565],{"class":179,"line":213},[177,528,339],{"class":183},[177,530,186],{"class":183},[177,532,533],{"class":189}," Nested",[177,535,536],{"class":193}," { ",[177,538,390],{"class":183},[177,540,541],{"class":189}," sum",[177,543,387],{"class":193},[177,545,390],{"class":183},[177,547,548],{"class":393}," a",[177,550,397],{"class":193},[177,552,252],{"class":183},[177,554,555],{"class":193}," a ",[177,557,558],{"class":183},"+",[177,560,561],{"class":429}," 5",[177,563,564],{"class":193},"; } }  ",[177,566,567],{"class":209},"\u002F\u002F no Outer link\n",[177,569,570,573,576,578,580,583,585,587,590],{"class":179,"line":222},[177,571,572],{"class":183},"  class",[177,574,575],{"class":189}," Inner",[177,577,536],{"class":193},[177,579,390],{"class":183},[177,581,582],{"class":189}," read",[177,584,249],{"class":193},[177,586,252],{"class":183},[177,588,589],{"class":193}," x; } }                  ",[177,591,592],{"class":209},"\u002F\u002F uses Outer's x\n",[177,594,595],{"class":179,"line":237},[177,596,264],{"class":193},[177,598,599,602,604,607,610,613,616],{"class":179,"line":261},[177,600,601],{"class":193},"Outer.Nested n ",[177,603,369],{"class":183},[177,605,606],{"class":183}," new",[177,608,609],{"class":193}," Outer.",[177,611,612],{"class":189},"Nested",[177,614,615],{"class":193},"();      ",[177,617,618],{"class":209},"\u002F\u002F no Outer instance required\n",[177,620,621,624,626,628,630,633,635,637,640],{"class":179,"line":418},[177,622,623],{"class":193},"Outer.Inner i ",[177,625,369],{"class":183},[177,627,606],{"class":183},[177,629,507],{"class":189},[177,631,632],{"class":193},"().",[177,634,318],{"class":183},[177,636,575],{"class":189},[177,638,639],{"class":193},"();  ",[177,641,642],{"class":209},"\u002F\u002F needs an enclosing Outer\n",[15,644,645,646,649],{},"Prefer ",[19,647,648],{},"static nested"," unless the class genuinely needs the outer instance: an inner\nclass silently retains a reference to its enclosing object, which is a frequent and\nhard-to-spot memory-leak cause.",[10,651,653],{"id":652},"final-assign-once-then-frozen","final: assign once, then frozen",[15,655,656,658,659,662,663,666,667,670,671,674,675,670,677,680,681,684,685,688],{},[45,657,47],{}," means ",[19,660,661],{},"assign exactly once",". For a ",[28,664,665],{},"variable"," that locks the value (primitive) or\nwhich object the reference points to (object) — though the object itself can still mutate.\nFor a ",[28,668,669],{},"method"," it bans ",[19,672,673],{},"overriding","; for a ",[28,676,329],{},[19,678,679],{},"extension"," entirely (think\n",[45,682,683],{},"String",", ",[45,686,687],{},"Integer",").",[168,690,692],{"className":170,"code":691,"language":172,"meta":173,"style":173},"final int MAX = 10;                 \u002F\u002F MAX = 11; would not compile\nfinal List\u003CString> xs = new ArrayList\u003C>();\nxs.add(\"ok\");                       \u002F\u002F mutating the object is fine\n\u002F\u002F xs = new ArrayList\u003C>();          \u002F\u002F reassigning the reference is not\n\nfinal class Money { }               \u002F\u002F cannot be subclassed\nclass Base { final void audit() {} } \u002F\u002F subclasses cannot override audit()\n",[45,693,694,713,732,752,760,766,781],{"__ignoreMap":173},[177,695,696,698,700,703,705,707,710],{"class":179,"line":180},[177,697,47],{"class":183},[177,699,228],{"class":183},[177,701,702],{"class":193}," MAX ",[177,704,369],{"class":183},[177,706,521],{"class":429},[177,708,709],{"class":193},";                 ",[177,711,712],{"class":209},"\u002F\u002F MAX = 11; would not compile\n",[177,714,715,717,720,722,725,727,729],{"class":179,"line":197},[177,716,47],{"class":183},[177,718,719],{"class":193}," List\u003C",[177,721,683],{"class":183},[177,723,724],{"class":193},"> xs ",[177,726,369],{"class":183},[177,728,606],{"class":183},[177,730,731],{"class":193}," ArrayList\u003C>();\n",[177,733,734,737,740,742,746,749],{"class":179,"line":213},[177,735,736],{"class":193},"xs.",[177,738,739],{"class":189},"add",[177,741,387],{"class":193},[177,743,745],{"class":744},"sZZnC","\"ok\"",[177,747,748],{"class":193},");                       ",[177,750,751],{"class":209},"\u002F\u002F mutating the object is fine\n",[177,753,754,757],{"class":179,"line":222},[177,755,756],{"class":209},"\u002F\u002F xs = new ArrayList\u003C>();",[177,758,759],{"class":209},"          \u002F\u002F reassigning the reference is not\n",[177,761,762],{"class":179,"line":237},[177,763,765],{"emptyLinePlaceholder":764},true,"\n",[177,767,768,770,772,775,778],{"class":179,"line":261},[177,769,47],{"class":183},[177,771,186],{"class":183},[177,773,774],{"class":189}," Money",[177,776,777],{"class":193}," { }               ",[177,779,780],{"class":209},"\u002F\u002F cannot be subclassed\n",[177,782,783,785,788,790,792,795,798,801],{"class":179,"line":418},[177,784,329],{"class":183},[177,786,787],{"class":189}," Base",[177,789,536],{"class":193},[177,791,47],{"class":183},[177,793,794],{"class":183}," void",[177,796,797],{"class":189}," audit",[177,799,800],{"class":193},"() {} } ",[177,802,803],{"class":209},"\u002F\u002F subclasses cannot override audit()\n",[15,805,806,808,809,811,812,815,816,819,820,822,823,825,826,829,830,832],{},[45,807,47],{}," applies to locals, fields, and parameters, and any local captured by a lambda must\nbe ",[45,810,47],{}," or ",[19,813,814],{},"effectively final",". A ",[19,817,818],{},"blank final"," is a ",[45,821,47],{}," field declared without\nan initializer; it must be set exactly once in every constructor (a static blank final, in\na ",[45,824,51],{}," block) — this is how immutable classes set fields from constructor arguments. A\n",[19,827,828],{},"final parameter"," simply can't be reassigned in the body. On methods and classes, ",[45,831,47],{},"\nboth protects invariants and lets the JIT inline more aggressively.",[10,834,836],{"id":835},"final-does-not-mean-immutable","final does not mean immutable",[15,838,839,840,842,843,846,847,850],{},"This is the trap interviewers reach for: ",[45,841,47],{}," freezes the ",[19,844,845],{},"reference",", never the\n",[19,848,849],{},"object's contents",".",[168,852,854],{"className":170,"code":853,"language":172,"meta":173,"style":173},"final StringBuilder sb = new StringBuilder(\"a\");\nsb.append(\"b\");                  \u002F\u002F allowed — the object is mutated\n\u002F\u002F sb = new StringBuilder();     \u002F\u002F not allowed — the reference is final\n",[45,855,856,878,897],{"__ignoreMap":173},[177,857,858,860,863,865,867,870,872,875],{"class":179,"line":180},[177,859,47],{"class":183},[177,861,862],{"class":193}," StringBuilder sb ",[177,864,369],{"class":183},[177,866,606],{"class":183},[177,868,869],{"class":189}," StringBuilder",[177,871,387],{"class":193},[177,873,874],{"class":744},"\"a\"",[177,876,877],{"class":193},");\n",[177,879,880,883,886,888,891,894],{"class":179,"line":197},[177,881,882],{"class":193},"sb.",[177,884,885],{"class":189},"append",[177,887,387],{"class":193},[177,889,890],{"class":744},"\"b\"",[177,892,893],{"class":193},");                  ",[177,895,896],{"class":209},"\u002F\u002F allowed — the object is mutated\n",[177,898,899,902],{"class":179,"line":213},[177,900,901],{"class":209},"\u002F\u002F sb = new StringBuilder();",[177,903,904],{"class":209},"     \u002F\u002F not allowed — the reference is final\n",[15,906,907,910,911,914,915,917,918,920],{},[19,908,909],{},"Immutability"," is a stronger, design-level property: all fields ",[45,912,913],{},"private final",", no\nsetters, defensive copies of mutable inputs and outputs, and usually a ",[45,916,47],{}," class so no\nsubclass can sneak mutable state in. ",[45,919,47],{}," is one ingredient of immutability, not the\nwhole recipe.",[10,922,924],{"id":923},"static-final-the-constant-idiom","static final: the constant idiom",[15,926,927,928,931,932,935,936,938,939,941,942,945,946,948,949,951],{},"Combine the two and you get the canonical ",[19,929,930],{},"constant",": ",[45,933,934],{},"static final"," with an\nUPPER_SNAKE_CASE name. ",[45,937,51],{}," gives one shared copy; ",[45,940,47],{}," makes it unassignable. The\ncompiler can ",[19,943,944],{},"inline"," ",[45,947,934],{}," primitive and ",[45,950,683],{}," constants for efficiency.",[168,953,955],{"className":170,"code":954,"language":172,"meta":173,"style":173},"public class Config {\n  public static final int MAX_RETRIES = 3;\n  public static final String APP_NAME = \"Interviews\";\n  \u002F\u002F a \"constant\" reference is still mutable underneath:\n  public static final List\u003CString> ROLES = List.of(\"admin\", \"user\"); \u002F\u002F truly fixed\n}\n",[45,956,957,968,990,1008,1013,1052],{"__ignoreMap":173},[177,958,959,961,963,966],{"class":179,"line":180},[177,960,158],{"class":183},[177,962,186],{"class":183},[177,964,965],{"class":189}," Config",[177,967,194],{"class":193},[177,969,970,972,975,978,980,983,985,988],{"class":179,"line":197},[177,971,240],{"class":183},[177,973,974],{"class":183}," static",[177,976,977],{"class":183}," final",[177,979,228],{"class":183},[177,981,982],{"class":193}," MAX_RETRIES ",[177,984,369],{"class":183},[177,986,987],{"class":429}," 3",[177,989,524],{"class":193},[177,991,992,994,996,998,1001,1003,1006],{"class":179,"line":213},[177,993,240],{"class":183},[177,995,974],{"class":183},[177,997,977],{"class":183},[177,999,1000],{"class":193}," String APP_NAME ",[177,1002,369],{"class":183},[177,1004,1005],{"class":744}," \"Interviews\"",[177,1007,524],{"class":193},[177,1009,1010],{"class":179,"line":222},[177,1011,1012],{"class":209},"  \u002F\u002F a \"constant\" reference is still mutable underneath:\n",[177,1014,1015,1017,1019,1021,1023,1025,1028,1030,1033,1036,1038,1041,1043,1046,1049],{"class":179,"line":237},[177,1016,240],{"class":183},[177,1018,974],{"class":183},[177,1020,977],{"class":183},[177,1022,719],{"class":193},[177,1024,683],{"class":183},[177,1026,1027],{"class":193},"> ROLES ",[177,1029,369],{"class":183},[177,1031,1032],{"class":193}," List.",[177,1034,1035],{"class":189},"of",[177,1037,387],{"class":193},[177,1039,1040],{"class":744},"\"admin\"",[177,1042,684],{"class":193},[177,1044,1045],{"class":744},"\"user\"",[177,1047,1048],{"class":193},"); ",[177,1050,1051],{"class":209},"\u002F\u002F truly fixed\n",[177,1053,1054],{"class":179,"line":261},[177,1055,264],{"class":193},[15,1057,1058,1059,1062,1063,1066,1067,1070,1071,850],{},"Remember the reference caveat: ",[45,1060,1061],{},"static final List\u003CString> X = new ArrayList\u003C>()"," can still\nbe ",[45,1064,1065],{},".add()","-ed to. For a genuinely constant collection use ",[45,1068,1069],{},"List.of(...)"," or\n",[45,1072,1073],{},"Collections.unmodifiableList(...)",[10,1075,1077],{"id":1076},"abstract-a-contract-demanding-an-override","abstract: a contract demanding an override",[15,1079,1080,1081,1084,1085,1088,1089,1092],{},"An ",[19,1082,1083],{},"abstract method"," declares a signature with no body — subclasses ",[28,1086,1087],{},"must"," implement it.\nAn ",[19,1090,1091],{},"abstract class"," can't be instantiated; it exists to be extended and may freely mix\nabstract methods, concrete methods, and state.",[168,1094,1096],{"className":170,"code":1095,"language":172,"meta":173,"style":173},"abstract class Shape {\n  abstract double area();              \u002F\u002F no body — subclass must supply it\n  void describe() { System.out.println(\"area=\" + area()); }  \u002F\u002F concrete is fine\n}\nclass Circle extends Shape {\n  double r;\n  double area() { return Math.PI * r * r; }\n}\n\u002F\u002F new Shape();   \u002F\u002F compile error — abstract class\n",[45,1097,1098,1110,1126,1156,1160,1174,1182,1205,1209],{"__ignoreMap":173},[177,1099,1100,1103,1105,1108],{"class":179,"line":180},[177,1101,1102],{"class":183},"abstract",[177,1104,186],{"class":183},[177,1106,1107],{"class":189}," Shape",[177,1109,194],{"class":193},[177,1111,1112,1115,1117,1120,1123],{"class":179,"line":197},[177,1113,1114],{"class":183},"  abstract",[177,1116,203],{"class":183},[177,1118,1119],{"class":189}," area",[177,1121,1122],{"class":193},"();              ",[177,1124,1125],{"class":209},"\u002F\u002F no body — subclass must supply it\n",[177,1127,1128,1131,1134,1137,1140,1142,1145,1148,1150,1153],{"class":179,"line":213},[177,1129,1130],{"class":183},"  void",[177,1132,1133],{"class":189}," describe",[177,1135,1136],{"class":193},"() { System.out.",[177,1138,1139],{"class":189},"println",[177,1141,387],{"class":193},[177,1143,1144],{"class":744},"\"area=\"",[177,1146,1147],{"class":183}," +",[177,1149,1119],{"class":189},[177,1151,1152],{"class":193},"()); }  ",[177,1154,1155],{"class":209},"\u002F\u002F concrete is fine\n",[177,1157,1158],{"class":179,"line":222},[177,1159,264],{"class":193},[177,1161,1162,1164,1167,1170,1172],{"class":179,"line":237},[177,1163,329],{"class":183},[177,1165,1166],{"class":189}," Circle",[177,1168,1169],{"class":183}," extends",[177,1171,1107],{"class":189},[177,1173,194],{"class":193},[177,1175,1176,1179],{"class":179,"line":261},[177,1177,1178],{"class":183},"  double",[177,1180,1181],{"class":193}," r;\n",[177,1183,1184,1186,1188,1190,1192,1195,1197,1200,1202],{"class":179,"line":418},[177,1185,1178],{"class":183},[177,1187,1119],{"class":189},[177,1189,249],{"class":193},[177,1191,252],{"class":183},[177,1193,1194],{"class":193}," Math.PI ",[177,1196,405],{"class":183},[177,1198,1199],{"class":193}," r ",[177,1201,405],{"class":183},[177,1203,1204],{"class":193}," r; }\n",[177,1206,1207],{"class":179,"line":439},[177,1208,264],{"class":193},[177,1210,1211,1214],{"class":179,"line":452},[177,1212,1213],{"class":209},"\u002F\u002F new Shape();",[177,1215,1216],{"class":209},"   \u002F\u002F compile error — abstract class\n",[15,1218,1219,1220,1222,1223,1226],{},"Any class containing even one abstract method must itself be declared ",[45,1221,1102],{},". Use it\nwhen you want shared code ",[28,1224,1225],{},"plus"," mandatory hooks for subclasses to fill in.",[10,1228,1230],{"id":1229},"why-abstract-clashes-with-final-static-and-private","Why abstract clashes with final, static, and private",[15,1232,1233,1235,1236,1239,1240,1243],{},[45,1234,1102],{}," means \"",[19,1237,1238],{},"must be overridden",".\" So it's contradictory with every modifier that\n",[19,1241,1242],{},"prevents"," overriding, and the compiler rejects those combinations outright:",[76,1245,1246,1256],{},[79,1247,1248],{},[82,1249,1250,1253],{},[85,1251,1252],{},"Combination",[85,1254,1255],{},"Why it's illegal",[102,1257,1258,1273,1283,1295,1305],{},[82,1259,1260,1265],{},[107,1261,1262],{},[45,1263,1264],{},"abstract final",[107,1266,1267,1269,1270,1272],{},[45,1268,47],{}," forbids overriding; ",[45,1271,1102],{}," requires it",[82,1274,1275,1280],{},[107,1276,1277],{},[45,1278,1279],{},"abstract static",[107,1281,1282],{},"static methods aren't polymorphic — can't be overridden",[82,1284,1285,1290],{},[107,1286,1287],{},[45,1288,1289],{},"abstract private",[107,1291,1292,1294],{},[45,1293,111],{}," isn't inherited, so nothing can override it",[82,1296,1297,1302],{},[107,1298,1299],{},[45,1300,1301],{},"abstract synchronized",[107,1303,1304],{},"there's no body, so nothing to lock",[82,1306,1307,1312],{},[107,1308,1309],{},[45,1310,1311],{},"abstract native",[107,1313,1314,945,1317,1320,1321,1323],{},[45,1315,1316],{},"native",[28,1318,1319],{},"has"," an external body; ",[45,1322,1102],{}," has none",[168,1325,1327],{"className":170,"code":1326,"language":172,"meta":173,"style":173},"abstract class C {\n  \u002F\u002F abstract final  void a();   \u002F\u002F error\n  \u002F\u002F abstract static  void b();  \u002F\u002F error\n  \u002F\u002F abstract private void c();  \u002F\u002F error\n}\n",[45,1328,1329,1340,1348,1356,1363],{"__ignoreMap":173},[177,1330,1331,1333,1335,1338],{"class":179,"line":180},[177,1332,1102],{"class":183},[177,1334,186],{"class":183},[177,1336,1337],{"class":189}," C",[177,1339,194],{"class":193},[177,1341,1342,1345],{"class":179,"line":197},[177,1343,1344],{"class":209},"  \u002F\u002F abstract final  void a();",[177,1346,1347],{"class":209},"   \u002F\u002F error\n",[177,1349,1350,1353],{"class":179,"line":213},[177,1351,1352],{"class":209},"  \u002F\u002F abstract static  void b();",[177,1354,1355],{"class":209},"  \u002F\u002F error\n",[177,1357,1358,1361],{"class":179,"line":222},[177,1359,1360],{"class":209},"  \u002F\u002F abstract private void c();",[177,1362,1355],{"class":209},[177,1364,1365],{"class":179,"line":237},[177,1366,264],{"class":193},[15,1368,1369,1370,1373,1374,1377,1378,1380,1381,1383,1384,1386],{},"More broadly: a member can carry ",[19,1371,1372],{},"at most one"," access modifier (",[45,1375,1376],{},"public private int x;","\nis meaningless), and ",[45,1379,1102],{}," is only compatible with ",[45,1382,158],{},"\u002F",[45,1385,143],{},"\u002Fpackage-private\n— anything that keeps the door to overriding open.",[10,1388,1390],{"id":1389},"transient-and-volatile-two-field-level-signals-to-the-jvm","transient and volatile: two field-level signals to the JVM",[15,1392,1393,1394,1397,1398,1401,1402,1405,1406,684,1409,684,1412,1415,1416,1419,1420,1423,1424,1427,1428,1431],{},"These both modify ",[28,1395,1396],{},"how a field is treated by the runtime"," rather than its visibility.\n",[45,1399,1400],{},"transient"," marks a field to be ",[19,1403,1404],{},"skipped during serialization","; on deserialization it\nreturns as its default (",[45,1407,1408],{},"0",[45,1410,1411],{},"false",[45,1413,1414],{},"null","). ",[45,1417,1418],{},"volatile"," tells the JVM a field may be\ntouched by ",[19,1421,1422],{},"multiple threads",", so every read hits ",[19,1425,1426],{},"main memory"," and every write is\nimmediately visible — plus it establishes a ",[19,1429,1430],{},"happens-before"," ordering.",[168,1433,1435],{"className":170,"code":1434,"language":172,"meta":173,"style":173},"class Session implements Serializable {\n  String user;                          \u002F\u002F serialized normally\n  transient String authToken;           \u002F\u002F skipped — restored as null\n}\n\nclass Worker {\n  private volatile boolean running = true;  \u002F\u002F visibility across threads\n  void stop() { running = false; }          \u002F\u002F immediately seen by run()\n  void run() { while (running) { \u002F* ... *\u002F } } \u002F\u002F won't loop forever\n}\n",[45,1436,1437,1452,1460,1471,1475,1479,1488,1512,1533,1557],{"__ignoreMap":173},[177,1438,1439,1441,1444,1447,1450],{"class":179,"line":180},[177,1440,329],{"class":183},[177,1442,1443],{"class":189}," Session",[177,1445,1446],{"class":183}," implements",[177,1448,1449],{"class":189}," Serializable",[177,1451,194],{"class":193},[177,1453,1454,1457],{"class":179,"line":197},[177,1455,1456],{"class":193},"  String user;                          ",[177,1458,1459],{"class":209},"\u002F\u002F serialized normally\n",[177,1461,1462,1465,1468],{"class":179,"line":213},[177,1463,1464],{"class":183},"  transient",[177,1466,1467],{"class":193}," String authToken;           ",[177,1469,1470],{"class":209},"\u002F\u002F skipped — restored as null\n",[177,1472,1473],{"class":179,"line":222},[177,1474,264],{"class":193},[177,1476,1477],{"class":179,"line":237},[177,1478,765],{"emptyLinePlaceholder":764},[177,1480,1481,1483,1486],{"class":179,"line":261},[177,1482,329],{"class":183},[177,1484,1485],{"class":189}," Worker",[177,1487,194],{"class":193},[177,1489,1490,1492,1495,1498,1501,1503,1506,1509],{"class":179,"line":418},[177,1491,200],{"class":183},[177,1493,1494],{"class":183}," volatile",[177,1496,1497],{"class":183}," boolean",[177,1499,1500],{"class":193}," running ",[177,1502,369],{"class":183},[177,1504,1505],{"class":429}," true",[177,1507,1508],{"class":193},";  ",[177,1510,1511],{"class":209},"\u002F\u002F visibility across threads\n",[177,1513,1514,1516,1519,1522,1524,1527,1530],{"class":179,"line":439},[177,1515,1130],{"class":183},[177,1517,1518],{"class":189}," stop",[177,1520,1521],{"class":193},"() { running ",[177,1523,369],{"class":183},[177,1525,1526],{"class":429}," false",[177,1528,1529],{"class":193},"; }          ",[177,1531,1532],{"class":209},"\u002F\u002F immediately seen by run()\n",[177,1534,1535,1537,1540,1542,1545,1548,1551,1554],{"class":179,"line":452},[177,1536,1130],{"class":183},[177,1538,1539],{"class":189}," run",[177,1541,249],{"class":193},[177,1543,1544],{"class":183},"while",[177,1546,1547],{"class":193}," (running) { ",[177,1549,1550],{"class":209},"\u002F* ... *\u002F",[177,1552,1553],{"class":193}," } } ",[177,1555,1556],{"class":209},"\u002F\u002F won't loop forever\n",[177,1558,1560],{"class":179,"line":1559},10,[177,1561,264],{"class":193},[15,1563,1564,1565,1567,1568,1570,1571,1573,1574,1576,1577,1580],{},"Use ",[45,1566,1400],{}," for sensitive data (passwords, tokens), recomputable caches, or\nnon-serializable fields — it has no effect on ",[45,1569,51],{}," fields, which aren't part of an\ninstance's serialized state anyway. Use ",[45,1572,1418],{}," for simple flags and safe publication of\na single value, but remember it does ",[19,1575,274],{}," give atomicity: ",[45,1578,1579],{},"volatile int x; x++;"," is\nstill a race because read-modify-write isn't atomic.",[10,1582,1584],{"id":1583},"synchronized-mutual-exclusion","synchronized: mutual exclusion",[15,1586,1587,1588,1591,1592,1595,1596,1599],{},"For compound atomicity, you reach for ",[45,1589,1590],{},"synchronized",", which provides ",[19,1593,1594],{},"mutual exclusion",":\nonly one thread at a time holds an object's ",[19,1597,1598],{},"monitor lock",", so the guarded code runs\nwithout interference (and gets the same happens-before visibility guarantees).",[168,1601,1603],{"className":170,"code":1602,"language":172,"meta":173,"style":173},"class Counter {\n  private int count;\n  synchronized void inc() { count++; }       \u002F\u002F locks on 'this'\n\n  private final Object lock = new Object();\n  void update() {\n    synchronized (lock) { count += 2; }      \u002F\u002F locks a private monitor\n  }\n}\n",[45,1604,1605,1613,1622,1644,1648,1667,1677,1697,1702],{"__ignoreMap":173},[177,1606,1607,1609,1611],{"class":179,"line":180},[177,1608,329],{"class":183},[177,1610,332],{"class":189},[177,1612,194],{"class":193},[177,1614,1615,1617,1619],{"class":179,"line":197},[177,1616,200],{"class":183},[177,1618,228],{"class":183},[177,1620,1621],{"class":193}," count;\n",[177,1623,1624,1627,1629,1632,1635,1638,1641],{"class":179,"line":213},[177,1625,1626],{"class":183},"  synchronized",[177,1628,794],{"class":183},[177,1630,1631],{"class":189}," inc",[177,1633,1634],{"class":193},"() { count",[177,1636,1637],{"class":183},"++",[177,1639,1640],{"class":193},"; }       ",[177,1642,1643],{"class":209},"\u002F\u002F locks on 'this'\n",[177,1645,1646],{"class":179,"line":222},[177,1647,765],{"emptyLinePlaceholder":764},[177,1649,1650,1652,1654,1657,1659,1661,1664],{"class":179,"line":237},[177,1651,200],{"class":183},[177,1653,977],{"class":183},[177,1655,1656],{"class":193}," Object lock ",[177,1658,369],{"class":183},[177,1660,606],{"class":183},[177,1662,1663],{"class":189}," Object",[177,1665,1666],{"class":193},"();\n",[177,1668,1669,1671,1674],{"class":179,"line":261},[177,1670,1130],{"class":183},[177,1672,1673],{"class":189}," update",[177,1675,1676],{"class":193},"() {\n",[177,1678,1679,1682,1685,1688,1691,1694],{"class":179,"line":418},[177,1680,1681],{"class":183},"    synchronized",[177,1683,1684],{"class":193}," (lock) { count ",[177,1686,1687],{"class":183},"+=",[177,1689,1690],{"class":429}," 2",[177,1692,1693],{"class":193},"; }      ",[177,1695,1696],{"class":209},"\u002F\u002F locks a private monitor\n",[177,1698,1699],{"class":179,"line":439},[177,1700,1701],{"class":193},"  }\n",[177,1703,1704],{"class":179,"line":452},[177,1705,264],{"class":193},[15,1707,1708,1709,1711,1712,1714,1715,1718,1719,1722,1723,1726,1727,1729],{},"A synchronized ",[28,1710,669],{}," locks ",[45,1713,55],{}," (or the ",[45,1716,1717],{},"Class"," object if static); a synchronized\n",[28,1720,1721],{},"block"," locks the object you name. Prefer a ",[19,1724,1725],{},"private lock object"," over locking ",[45,1728,55],{},", so\nunrelated outside code can't interfere with your lock.",[10,1731,1733],{"id":1732},"this-and-super-the-current-and-parent-objects","this and super: the current and parent objects",[15,1735,1736,1738,1739,1742,1743,1746,1747,1738,1750,1753,1754,1757,1758,850],{},[45,1737,55],{}," references the ",[19,1740,1741],{},"current object"," — used to disambiguate a field from a same-named\nparameter, to pass the current object along, and to chain to another constructor via\n",[45,1744,1745],{},"this(...)",". ",[45,1748,1749],{},"super",[19,1751,1752],{},"parent class"," — to call its constructor ",[45,1755,1756],{},"super(...)","\nor reach an overridden method ",[45,1759,1760],{},"super.method()",[168,1762,1764],{"className":170,"code":1763,"language":172,"meta":173,"style":173},"class Animal {\n  String sound() { return \"...\"; }\n  Animal(String name) { \u002F* ... *\u002F }\n}\nclass Dog extends Animal {\n  Dog() { super(\"Rex\"); }                  \u002F\u002F parent ctor — must be first statement\n  @Override String sound() { return super.sound() + \"woof\"; }\n}\n",[45,1765,1766,1775,1793,1811,1815,1828,1848,1881],{"__ignoreMap":173},[177,1767,1768,1770,1773],{"class":179,"line":180},[177,1769,329],{"class":183},[177,1771,1772],{"class":189}," Animal",[177,1774,194],{"class":193},[177,1776,1777,1780,1783,1785,1787,1790],{"class":179,"line":197},[177,1778,1779],{"class":193},"  String ",[177,1781,1782],{"class":189},"sound",[177,1784,249],{"class":193},[177,1786,252],{"class":183},[177,1788,1789],{"class":744}," \"...\"",[177,1791,1792],{"class":193},"; }\n",[177,1794,1795,1798,1801,1804,1806,1808],{"class":179,"line":213},[177,1796,1797],{"class":189},"  Animal",[177,1799,1800],{"class":193},"(String ",[177,1802,1803],{"class":393},"name",[177,1805,397],{"class":193},[177,1807,1550],{"class":209},[177,1809,1810],{"class":193}," }\n",[177,1812,1813],{"class":179,"line":222},[177,1814,264],{"class":193},[177,1816,1817,1819,1822,1824,1826],{"class":179,"line":237},[177,1818,329],{"class":183},[177,1820,1821],{"class":189}," Dog",[177,1823,1169],{"class":183},[177,1825,1772],{"class":189},[177,1827,194],{"class":193},[177,1829,1830,1833,1835,1837,1839,1842,1845],{"class":179,"line":261},[177,1831,1832],{"class":189},"  Dog",[177,1834,249],{"class":193},[177,1836,1749],{"class":429},[177,1838,387],{"class":193},[177,1840,1841],{"class":744},"\"Rex\"",[177,1843,1844],{"class":193},"); }                  ",[177,1846,1847],{"class":209},"\u002F\u002F parent ctor — must be first statement\n",[177,1849,1850,1853,1856,1858,1860,1862,1864,1867,1869,1871,1874,1876,1879],{"class":179,"line":418},[177,1851,1852],{"class":193},"  @",[177,1854,1855],{"class":183},"Override",[177,1857,243],{"class":193},[177,1859,1782],{"class":189},[177,1861,249],{"class":193},[177,1863,252],{"class":183},[177,1865,1866],{"class":429}," super",[177,1868,850],{"class":193},[177,1870,1782],{"class":189},[177,1872,1873],{"class":193},"() ",[177,1875,558],{"class":183},[177,1877,1878],{"class":744}," \"woof\"",[177,1880,1792],{"class":193},[177,1882,1883],{"class":179,"line":439},[177,1884,264],{"class":193},[15,1886,1887,1888,278,1890,1892,1893,1896,1897,1899,1900,1903,1904,1907,1908,1910,1911,1913,1914,1916],{},"Both ",[45,1889,1745],{},[45,1891,1756],{}," must be the ",[19,1894,1895],{},"first statement"," in a constructor, so you\nuse at most one. If you omit ",[45,1898,1756],{},", the compiler inserts an implicit no-arg\n",[45,1901,1902],{},"super()"," — which is exactly why a parent with ",[28,1905,1906],{},"only"," a parameterized constructor forces\nevery subclass to call ",[45,1909,1756],{}," explicitly. And ",[45,1912,55],{}," is unavailable in any ",[45,1915,51],{},"\ncontext, since there's no current instance.",[10,1918,1920],{"id":1919},"instanceof-and-pattern-matching","instanceof and pattern matching",[15,1922,1923,1926,1927,1930,1931,1934],{},[45,1924,1925],{},"instanceof"," tests whether an object is an instance of a type (or subtype), returning a\n",[45,1928,1929],{},"boolean",". Since Java 16, ",[19,1932,1933],{},"pattern matching"," binds the result to a typed variable in one\nstep, eliminating the manual cast.",[168,1936,1938],{"className":170,"code":1937,"language":172,"meta":173,"style":173},"Object o = \"hello\";\n\nif (o instanceof String) {          \u002F\u002F classic form\n  String s = (String) o;            \u002F\u002F explicit cast needed\n  System.out.println(s.length());\n}\n\nif (o instanceof String s) {        \u002F\u002F pattern matching (Java 16+)\n  System.out.println(s.length());   \u002F\u002F 's' is already typed\n}\n",[45,1939,1940,1952,1956,1972,1985,2001,2005,2009,2023,2039],{"__ignoreMap":173},[177,1941,1942,1945,1947,1950],{"class":179,"line":180},[177,1943,1944],{"class":193},"Object o ",[177,1946,369],{"class":183},[177,1948,1949],{"class":744}," \"hello\"",[177,1951,524],{"class":193},[177,1953,1954],{"class":179,"line":197},[177,1955,765],{"emptyLinePlaceholder":764},[177,1957,1958,1961,1964,1966,1969],{"class":179,"line":213},[177,1959,1960],{"class":183},"if",[177,1962,1963],{"class":193}," (o ",[177,1965,1925],{"class":183},[177,1967,1968],{"class":193}," String) {          ",[177,1970,1971],{"class":209},"\u002F\u002F classic form\n",[177,1973,1974,1977,1979,1982],{"class":179,"line":222},[177,1975,1976],{"class":193},"  String s ",[177,1978,369],{"class":183},[177,1980,1981],{"class":193}," (String) o;            ",[177,1983,1984],{"class":209},"\u002F\u002F explicit cast needed\n",[177,1986,1987,1990,1992,1995,1998],{"class":179,"line":237},[177,1988,1989],{"class":193},"  System.out.",[177,1991,1139],{"class":189},[177,1993,1994],{"class":193},"(s.",[177,1996,1997],{"class":189},"length",[177,1999,2000],{"class":193},"());\n",[177,2002,2003],{"class":179,"line":261},[177,2004,264],{"class":193},[177,2006,2007],{"class":179,"line":418},[177,2008,765],{"emptyLinePlaceholder":764},[177,2010,2011,2013,2015,2017,2020],{"class":179,"line":439},[177,2012,1960],{"class":183},[177,2014,1963],{"class":193},[177,2016,1925],{"class":183},[177,2018,2019],{"class":193}," String s) {        ",[177,2021,2022],{"class":209},"\u002F\u002F pattern matching (Java 16+)\n",[177,2024,2025,2027,2029,2031,2033,2036],{"class":179,"line":452},[177,2026,1989],{"class":193},[177,2028,1139],{"class":189},[177,2030,1994],{"class":193},[177,2032,1997],{"class":189},[177,2034,2035],{"class":193},"());   ",[177,2037,2038],{"class":209},"\u002F\u002F 's' is already typed\n",[177,2040,2041],{"class":179,"line":1559},[177,2042,264],{"class":193},[15,2044,2045,2046,2048,2049,2051,2052,2054,2055,2058],{},"Two facts worth memorizing: ",[45,2047,1925],{}," on ",[45,2050,1414],{}," is always ",[45,2053,1411],{}," (a built-in null\nguard), and it's the standard way to make a ",[19,2056,2057],{},"downcast"," safe before performing it.",[10,2060,2062],{"id":2061},"var-and-the-keywords-java-never-used","var, and the keywords Java never used",[15,2064,2065,2067,2068,2071,2072,2075,2076,2078,2079,278,2082,2085,2086,2088],{},[45,2066,58],{}," (Java 10+) provides ",[19,2069,2070],{},"local variable type inference"," — but it is a ",[19,2073,2074],{},"reserved type\nname",", not a true keyword. That distinction is testable: because it isn't a keyword you can\nstill use ",[45,2077,58],{}," as a variable, method, or package name (just not a class name). Meanwhile\ntwo genuine reserved keywords, ",[45,2080,2081],{},"goto",[45,2083,2084],{},"const",", exist but do ",[19,2087,73],{}," — reserved so C\u002FC++\nprogrammers wouldn't trip on them and so the language could repurpose them later (it never\ndid).",[168,2090,2092],{"className":170,"code":2091,"language":172,"meta":173,"style":173},"var list = new ArrayList\u003CString>();  \u002F\u002F inferred ArrayList\u003CString>\nvar count = 10;                      \u002F\u002F int — still statically typed\nint var = 5;                         \u002F\u002F legal! 'var' as an identifier\n\n\u002F\u002F int goto = 5;    \u002F\u002F compile error — reserved but unused keyword\n\u002F\u002F int const = 1;   \u002F\u002F compile error — reserved but unused keyword\n",[45,2093,2094,2116,2133,2150,2154,2162],{"__ignoreMap":173},[177,2095,2096,2098,2101,2103,2105,2108,2110,2113],{"class":179,"line":180},[177,2097,58],{"class":183},[177,2099,2100],{"class":193}," list ",[177,2102,369],{"class":183},[177,2104,606],{"class":183},[177,2106,2107],{"class":193}," ArrayList\u003C",[177,2109,683],{"class":183},[177,2111,2112],{"class":193},">();  ",[177,2114,2115],{"class":209},"\u002F\u002F inferred ArrayList\u003CString>\n",[177,2117,2118,2120,2123,2125,2127,2130],{"class":179,"line":197},[177,2119,58],{"class":183},[177,2121,2122],{"class":193}," count ",[177,2124,369],{"class":183},[177,2126,521],{"class":429},[177,2128,2129],{"class":193},";                      ",[177,2131,2132],{"class":209},"\u002F\u002F int — still statically typed\n",[177,2134,2135,2137,2140,2142,2144,2147],{"class":179,"line":213},[177,2136,390],{"class":183},[177,2138,2139],{"class":193}," var ",[177,2141,369],{"class":183},[177,2143,561],{"class":429},[177,2145,2146],{"class":193},";                         ",[177,2148,2149],{"class":209},"\u002F\u002F legal! 'var' as an identifier\n",[177,2151,2152],{"class":179,"line":222},[177,2153,765],{"emptyLinePlaceholder":764},[177,2155,2156,2159],{"class":179,"line":237},[177,2157,2158],{"class":209},"\u002F\u002F int goto = 5;",[177,2160,2161],{"class":209},"    \u002F\u002F compile error — reserved but unused keyword\n",[177,2163,2164,2167],{"class":179,"line":261},[177,2165,2166],{"class":209},"\u002F\u002F int const = 1;",[177,2168,2169],{"class":209},"   \u002F\u002F compile error — reserved but unused keyword\n",[15,2171,2172,2174,2175,2178,2179,2182,2183,2186,2187,2189,2190,2192,2193,1383,2196,2189,2199,2201,2202,2204,2205,2208],{},[45,2173,58],{}," works only on locals ",[28,2176,2177],{},"with an initializer"," — never fields, parameters, return types,\nor ",[45,2180,2181],{},"var x;"," \u002F ",[45,2184,2185],{},"var x = null;",". Java uses ",[45,2188,47],{}," where C uses ",[45,2191,2084],{},", and labeled\n",[45,2194,2195],{},"break",[45,2197,2198],{},"continue",[45,2200,2081],{},". (Two more rarities round out the trivia: ",[45,2203,1316],{},"\nmarks a method implemented in non-Java code via JNI, and ",[45,2206,2207],{},"strictfp"," forced IEEE-754 math —\nnow a no-op since Java 17 made all floating-point strict.)",[10,2210,2212],{"id":2211},"recap","Recap",[15,2214,2215,2216,2219,2220,2222,2223,2225,2226,2228,2229,2233,2234,1746,2236,2240,2241,2243,2244,2248,2249,684,2251,39,2253,2255,2256,684,2260,39,2264,2268,2269,1383,2273,2277,2278,2282,2283,2287,2288,2291],{},"Java's modifiers each answer one precise question. ",[19,2217,2218],{},"Access modifiers"," —\n",[45,2221,111],{}," \u003C default \u003C ",[45,2224,143],{}," \u003C ",[45,2227,158],{}," — control visibility, narrowest by default.\n",[19,2230,2231],{},[45,2232,51],{}," binds a member to the class with one shared copy and no ",[45,2235,55],{},[19,2237,2238],{},[45,2239,47],{},"\nmeans assign-once: it freezes references, methods (no override), and classes (no extend),\nbut it does ",[19,2242,274],{}," make objects immutable — that's a whole-design discipline. ",[19,2245,2246],{},[45,2247,1102],{},"\ndemands an override, which is why it clashes with ",[45,2250,47],{},[45,2252,51],{},[45,2254,111],{},".\nThread-aware keywords — ",[19,2257,2258],{},[45,2259,1400],{},[19,2261,2262],{},[45,2263,1418],{},[19,2265,2266],{},[45,2267,1590],{}," — govern\nserialization and concurrency, while ",[19,2270,2271],{},[45,2272,55],{},[19,2274,2275],{},[45,2276,1749],{}," navigate the object hierarchy,\n",[19,2279,2280],{},[45,2281,1925],{}," (with pattern matching) makes downcasts safe, and ",[19,2284,2285],{},[45,2286,58],{}," infers local\ntypes without ever being a real keyword. Learn the ",[28,2289,2290],{},"reason"," behind each rule and the\ncombinations sort themselves out.",[2293,2294,2295],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}",{"title":173,"searchDepth":197,"depth":197,"links":2297},[2298,2299,2300,2301,2302,2303,2304,2305,2306,2307,2308,2309,2310,2311,2312],{"id":12,"depth":197,"text":13},{"id":62,"depth":197,"text":63},{"id":300,"depth":197,"text":301},{"id":480,"depth":197,"text":481},{"id":652,"depth":197,"text":653},{"id":835,"depth":197,"text":836},{"id":923,"depth":197,"text":924},{"id":1076,"depth":197,"text":1077},{"id":1229,"depth":197,"text":1230},{"id":1389,"depth":197,"text":1390},{"id":1583,"depth":197,"text":1584},{"id":1732,"depth":197,"text":1733},{"id":1919,"depth":197,"text":1920},{"id":2061,"depth":197,"text":2062},{"id":2211,"depth":197,"text":2212},"A guide to Java keywords and modifiers — the four access levels, static vs instance, final variables\u002Fmethods\u002Fclasses, abstract and its illegal combos, transient, volatile, synchronized, this\u002Fsuper, instanceof, and var.","medium","md","Java",{},"\u002Fblog\u002Fjava-keywords-modifiers-static-final","\u002Fjava\u002Ffundamentals\u002Fkeywords-modifiers",{"title":5,"description":2313},"blog\u002Fjava-keywords-modifiers-static-final","Keywords & Modifiers","Fundamentals","fundamentals","2026-06-20","gaSmvd8LIjndz5QHh1HDX2bJgfdg35FbMC_PEr2bR6k",1782244090585]