java lesson4

advertisement
Java Programming Language
LESSON 4 ( B OXED TYPES, OVERLOADING, OVERRIDING, I NHERITANCE )
Hayk Avdalyan
Java boxed types
Primitive type
Wrapper class
boolean
Boolean
byte
Byte
char
Character
float
Float
int
Integer
long
Long
short
Short
double
Double
Hayk Avdalyan
Cast/Parse
What do you think about the code above?
Hayk Avdalyan
Cast/Parse
ERROR
Cannot cast from String to int
Hayk Avdalyan
Cast/Parse
The correct way
Hayk Avdalyan
Cast/Parse
Also
a)
The Byte class provides the parseByte method,
b) The Long class the parseLong method,
c)
The Short class the parseShort method,
d) The Float class the parseFloat method, and
e) The Double class the parseDouble method.
Hayk Avdalyan
Access Modifiers
Hayk Avdalyan
Constructors
Constructors have the same name as the class
They do not have any return type
Hayk Avdalyan
Method overloading
Within the same class, you can create two methods of the same name but differs in the number
of arguments and their types.
This is called method overloading.
Note that changing the return type alone is not allowed to overload a method
Hayk Avdalyan
Inheritance
Hayk Avdalyan
Inheritance (IS-A) and (HAS-A)
Hayk Avdalyan
Method overriding
Method overriding occurs when a class inherits a method from a super class but provides its own
implementation of that method
Hayk Avdalyan
Method overriding
OR
Hayk Avdalyan
Task
Create your own project using inheritance
(minimum 5 objects)
Hayk Avdalyan
Download