• Nie Znaleziono Wyników

Exceptions, equals(), casting

N/A
N/A
Protected

Academic year: 2021

Share "Exceptions, equals(), casting"

Copied!
2
0
0

Pełen tekst

(1)

DPOB LI0 Object programming - classes 10

This document contains information about laboratory exercises.

Object programming - classes 10

Subjects - Null, exceptions, runtime type checking, methods equals() i hashcode()

1. Empty object - null.

1. Download and import to eclipse project for today laboratories.

2. Create new class and define 2 variables, first of type String and second of type int.

3. Write to the console values of objects created in point b). What are the default values of objects and variables ? Can we set object value to null

? How check if an object is not-null ?

4. What happen if we invoke method on object that have assign null value

?

2. Exceptions

1. In package Exceptions create new class A extending class Exception.

2. In class Exception, in method two() between writing to the console add condition, when variable isException is equals true throw an exception A().

3. Correct error by catching throwed exception method one.

4. Add to try and catch block f inally. Inside write to the console commu- nicate 00P erf ormingF inally00.

5. In package Exceptions create class B which inherits from class A. Now, in class Exception when variable isException is equals f alse throw an exception B(”Exception B”) (with some string in constructor).

6. After catching exception B write on the console message carried by this exception.

7. In method one after catching exception throw another exception of type RuntimeException(). What is the difference when you change it to thro- wing exception of type A or throw e ?

3. Runtime type checking

1. Analyze program Rzutowanie.java.

2. Check if it is possible to cast (a− >b,b− >a,a− >Exception,b− >Exception).

1

(2)

DPOB LI0 Object programming - classes 10

4. Methods equals() and hashcode()

1. Read in Java documentation for method equals of class Object. What conditions should the function equals() satisfy?

2. Analyze file Car.java, pay attention how method equals looks like!

3. Write method equals in class BigCar such that it would work correctly?

2

Cytaty

Powiązane dokumenty

Implement an unbounded queue (using non-sequential memory storage – the linked list) as a template structure (aimed at storing values of any type), and a set of methods operating

Write a program which implements an unbounded sorted list (using the single or double- linked list) as a template structure (aimed at storing values of any type and ordering them

Class L of selfdecomposable probability distributions (known also as Levy class L probability measures) appears in probability theory as the solution to the central limit problem..

otwarta została placówka duszpasterska w Suwałkach (erygowanie domu zakonnego 26 listopada 1981 r.). został erygowany dom zakonny przy małej publicznej kaplicy 5. Zaraz

In order to investigate the sensitivity of urban drainage models to the spatial-temporal resolution of rainfall inputs, the high-resolution precipitation data for the nine (9)

Voor de kosten analyse van de kranen is de gelimiteerde data gebruikt uit World Cargo News.. Voor de kosten analyse van kade wanden is een promotie werk gevonden dat de vragen van

To calulate the probability it is necessary to divide this quantity by Γ(U, V, N, ∆U ), which is the number of microstates of the system of energy between U and U + ∆U..

The above theorem was offered as a problem at the Polish Mathematical Olympiad in 1990..