This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
AJP/hw1/answers.tex
2022-09-25 18:35:18 +02:00

78 lines
2.1 KiB
TeX

% vim: set ts=2 sw=2 et tw=80:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=2cm]{geometry}
\title{Howework 1 -- Advanced Java Programming}
\author{Claudio Maggioni}
\begin{document}
\maketitle
\section{Exercise A}
\begin{itemize}
\item
1: True
\item
2: False (Required only if the class implements Comparable)
\item
3: True
\item
4: False (== for objects checks for reference equality)
\item
5: False (it is indeed implemented by default - more precisely implemented
in Object - but the default implementation checks reference equality only)
\item
6: False (a child class of \texttt{Tiger} may include additional fields that
are mutable. However, all properties and behaviour accessible via a
reference of type \texttt{Tiger} type can be considered immutable)
\item
7: False (the class itself is not public)
\item
8: False (classes in the same package of \texttt{Tiger} can read the
\texttt{name} field)
\item
9: True (the constructor to implement must explicitly call \texttt{Tiger}'s
constructor with \texttt{super})
\item
10: False (the declared type is \texttt{Number}, the runtime type is
\texttt{Integer})
\end{itemize}
\section{Exercise B}
\begin{itemize}
\item
1: False (the only ``collection'' data structure based over an unboxed
primitive type is the array -- however arrays are not \texttt{java.util}
collections)
\item
2: True (if the \texttt{hashCode()} return value changes after the mutation
then the implementation of hashMap is unable to recognize it was inserted
previously)
\item
3: True
\item
4: True
\item
5: False (\texttt{finally} blocks are always evaluated)
\end{itemize}
\section{Exercise C}
\begin{itemize}
\item 1: True
\item 2: False
\item 3: True
\item 4: True (more precisely, double dispatch or 'virtual table' invocations
are used only for invoking the method in the class matching the object's
dynamic type)
\item 5: True (as the method called depends on the runtime or dynamic type of
the caller object)
\end{itemize}
\end{document}