\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Jianmin Feng (taotao)} \pdfinfo{ /Title (java-class-design-oca.pdf) /Creator (Cheatography) /Author (Jianmin Feng (taotao)) /Subject (Java Class Design (OCA) Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{1B752A} \definecolor{LightBackground}{HTML}{F7FAF8} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Java Class Design (OCA) Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Jianmin Feng (taotao)} via \textcolor{DarkBackground}{\uline{cheatography.com/79308/cs/19394/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Jianmin Feng (taotao) \\ \uline{cheatography.com/taotao} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 5th May, 2019.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Inheritance}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Why inheritance?}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{1. DRY(Don't Repeat Youself): No copy and paste, use has a (composition), is a ( inheritance)} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{2. Extensible: easy to add/modify business logic and share the code)} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{Java inheritance}}} \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Single inheritance, one parent only , all instance variables and methods inheritated} \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{one parent could have multiple child classes} \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{parent/super/generic \textless{}- child/sub/specifc} \tn % Row Count 10 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Chaining constructor}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Chaining constructor}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{child constructor call parent constructor} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{reasons 1: private parent instance variable} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{reasons 2:clean and neat:compare: loosen restrict, add using setter(how about set is not logically OK)} \tn % Row Count 6 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{super() is always called explicitly()or implicitly in the first line of child constructor. -\textgreater{} if a class will be extended, it must has no argument constructor, or do not have any constructor.} \tn % Row Count 10 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{super.xxx(dot operation on super) won't follow first line rule of constructor.} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{More on protected}}} \tn % Row Count 13 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{Package private + subclass} \tn % Row Count 14 (+ 1) % Row 8 \SetRowColor{LightBackground} parent/child + different packages, access protected state/behavior from parent & 1) direct call 2)obj ref of {\bf{the child}} itself 3) obj ref of parent or other sub class can NOT. \tn % Row Count 19 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Overriding}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{in child change behavior of parent} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{1. same signature as parent} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{2. return type, same or subtype, primitive exact the same(no promoting and wrap)} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{3. accessible: same or wider} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{4. exception: same or fewer/subtype/runtime} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} private/static methods are hidden, not overriden & polymorphism applies only instance method \tn % Row Count 9 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{super. ( dot notation) to access parent state or behavior} \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{never hiding static member ( variable/method) or instance variable, bad practice, confusing.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Covariant returns}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{overriding method return a same or subtype of parent returned} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{exact the same for primitive return} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.88666 cm} x{2.09034 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Three Faces of Final}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{final variable}} & Constant \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} enum constants implicitly static final & constant used in switch \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{final method}} & no overriding \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} {\bf{final class}} & no extends, \seqsplit{java.lang.String} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Switch: literal,constant,enum, compiler time bind, variable or method return not, due to not known how many cases should be listed.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.08574 cm} x{1.89126 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Class/Object invocation order}} \tn % Row 0 \SetRowColor{LightBackground} 1 static var=default & child-\textgreater{}base \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} 2 static\{\}, explicit value assign to static var & base, in statement order \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} repeat 1,2 in child hierarchy order & -\textgreater{}child \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} 4 instance var=default & child-\textgreater{}base \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} 5 \{\},explicit value assign to instance var & base, in statement order \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} 6 constructor & base \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} repeat 4,5,6 in child hierarchy order & -\textgreater{}child \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{static initialization 1-3 execute only once when first class is loaded.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.18988 cm} x{2.78712 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Overloading}} \tn % Row 0 \SetRowColor{LightBackground} same name+different parameters & Signature=name+param,unique in a class \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{Others(return type,modifiers, exceptions) not matter} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{overloading matching order:} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{exact match -\textgreater{}promoting-\textgreater{}wrapper =\textgreater{}varargs (exact match,promoting,wrapper)} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Private methods redeclaration}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{not inheritated} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{can redecclare a method with same signature} \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{hiding static method}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{with static parent method, could not override} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{hiding - no polymorphism} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{4 overriding rules + static modifier} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Never hiding static methods in practice, confusing and bad habit} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Inherite variables}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{never overriding, always hiding if same name} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{when hiding a variables, using super and this to access parent and child} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{static and non static follow the same rule for hiding} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{private variables inherited but could not access directly.} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{never hiding variables in practice, confusing and hard to read code} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Abstract classes}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Why?}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{generalization, inheritance, overriding and polymorphism} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{simply code, beauty, no DRY} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{prevent improper instantiate of parent classes} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Abstract class rules}}} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{\textgreater{}=0 abstract methods} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{can't initialized} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{public /package private only, must be extends, so private or final is not allowed, protected is not logic/meaningful} \tn % Row Count 11 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{extends abstract class means overriden all abstracted methods or declared as abstract} \tn % Row Count 13 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{first concrete class must have implemented all abstract method directly or indirectly} \tn % Row Count 15 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Abstract methods}}} \tn % Row Count 16 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{in abstract class} \tn % Row Count 17 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{can not be private, final, static (must be overriden)} \tn % Row Count 19 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{no body, even \{\}} \tn % Row Count 20 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{overriding rules(4) must be followed: same signature, broader or same visibility, narrower or same return type, narrower or same exception throws/or runtime exception} \tn % Row Count 24 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Interface}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{public abstract interface ....\{\}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} public static final MIN\_DEPTH=3 & init at the statement \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} interface extends interface1,interface2,... & multiple extends allowed here \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} class inpluments interface1,interface2,... & multiple implements \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{can redecclare a method with same signature} \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{Rule for interface}}} \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} can not instantiated & may have no methods at all \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} public / default only & not private,final, protected for interface \tn % Row Count 16 (+ 3) % Row 8 \SetRowColor{LightBackground} all methods must be public & not private,final, protected for methods \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} abstract method by default & in java8, default, static methods with a body allowed \tn % Row Count 21 (+ 3) % Row 10 \SetRowColor{LightBackground} {\bf{default interface methods}} & java 8 \tn % Row Count 23 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{mainly for backward compatibility} \tn % Row Count 24 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{public default double calc()\{\}} \tn % Row Count 25 (+ 1) % Row 13 \SetRowColor{white} only in interface & can be redeclared as abstract or overriden with a different body \tn % Row Count 29 (+ 4) % Row 14 \SetRowColor{LightBackground} not static, final,or abstract ( overriden) & not private,protected \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Interface (cont)}} \tn % Row 15 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Multiple inheritance problem}}} \tn % Row Count 1 (+ 1) % Row 16 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{default method in interface, if not overriden, will cause compiler error if default methods with same signuature existed} \tn % Row Count 4 (+ 3) % Row 17 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{for interfaces without default methods, there is no this issue} \tn % Row Count 6 (+ 2) % Row 18 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{if default method is overriden, also no ambiguity problem.} \tn % Row Count 8 (+ 2) % Row 19 \SetRowColor{LightBackground} {\bf{Static method}} & java 8 above \tn % Row Count 9 (+ 1) % Row 20 \SetRowColor{white} public or default only & with a body \tn % Row Count 11 (+ 2) % Row 21 \SetRowColor{LightBackground} call with interface name, not with object ref & this avoid ambiguity cause be multiple inheritance \tn % Row Count 14 (+ 3) % Row 22 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{static methods in interface could be declared as default in sub interface} \tn % Row Count 16 (+ 2) % Row 23 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{designed to offer utility functions} \tn % Row Count 17 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{protected method in interface does not makes sense as has nothing to be shared with the subclass. it is just an interface. \newline muliple inheritance of type: \newline https://docs.oracle.com/javase/tutorial/java/IandI/multipleinheritance.htm \newline https://www.baeldung.com/java-static-default-methods \newline https://www.geeksforgeeks.org/difference-between-abstract-class-and-interface-in-java/} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Polymorphism}} \tn % Row 0 \SetRowColor{LightBackground} heart of inheritance ( \seqsplit{overriding+polymorphism)} & separate of concern, flexible/extensible coding \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{properties of an object to take on many different forms,compiling time- ref by super class/interface ref, at run time multiple behavior,based on the object itself} \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} multiple references(on the stack) ( ref of type of super class, interface), static binding & multiple object (on the heap )behaviors, dynamic binding \tn % Row Count 12 (+ 5) % Row 3 \SetRowColor{white} {\bf{Virtual methods}} & dynamic method dispatching \tn % Row Count 14 (+ 2) % Row 4 \SetRowColor{LightBackground} overriden methods & non private,static,final \tn % Row Count 16 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{a method in which the specific implementation is not determined until run time; at compiling time, parent ref is used, at run time, implementation based on the child obj referenced} \tn % Row Count 20 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Object casting}}} \tn % Row Count 21 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{implicit up casting ( child -\textgreater{}parent)} \tn % Row Count 22 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{explicity down casting( parent-\textgreater{}child)} \tn % Row Count 23 (+ 1) % Row 9 \SetRowColor{white} error for non-parent/child object casting & safe casting: \seqsplit{obj1.instanceOf(obj2)} \tn % Row Count 26 (+ 3) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Polymorphic parameters}}} \tn % Row Count 27 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{parameter is parent class or interface type} \tn % Row Count 28 (+ 1) % Row 12 \SetRowColor{LightBackground} passing the child obj or obj implemented the interface & auto up casting \tn % Row Count 31 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{a reference variable may only send messages that are available to its type.being available to an object != being declared inside an object} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{when Parent/Child not belong to same package}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{in extending class}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{protected parent members could be access directly. if by references, only by the ref of extending class itself} \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{ref variables of other child class or event he parent class COULD NOT access parent members inside extending calss} \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{constructor()}}} \tn % Row Count 8 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{if constructor missing access modifier ( package private), the child class could not instantiated.} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{if class to be extends, constructor must be public or protected, if in different package.} \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Pass by value vs by reference}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Both are passing by copy} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{the original content ( primitive value or object memory address) variables not affected} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{if passing a copy of obj address, changes to the object on the heap will shared with all references.} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{reassign the reference in callee will not affect the ref in caller} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{variable on stack frame, obj on heap} \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}