AJP/hw1/answers.tex

75 lines
1.9 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 - i.e.~in Object, but
the default implementation checks reference equality only)
\item
6: False (a child class of Tiger may include additional fields that
are mutable. However, all properties and behaviour accessible via a
reference of Tiger type is immutable)
\item
7: False (the class is not public)
\item
8: False (classes in the same package can read the name field)
\item
9: True (the constructor to implement must explicitly call Tiger's
constructor with super)
\item
10: False (the declared type is Number, the runtime type is 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)
\item
2: True (if the 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 (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}