computer science
src/.DS_Store
__MACOSX/src/._.DS_Store
src/Animal.java
src/Animal.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
@author
mrahman
*/
public
class
Animal
{
protected
int
i
;
public
void
eat
(){
System
.
out
.
println
(
"Animal eats."
);
}
}
__MACOSX/src/._Animal.java
src/Cat.java
src/Cat.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
@author
mrahman
*/
public
class
Cat
extends
Animal
{
}
__MACOSX/src/._Cat.java
src/Dog.java
src/Dog.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
@author
mrahman
*/
public
class
Dog
extends
Animal
{
public
void
run
(){
System
.
out
.
println
(
"Dog runs..."
);
}
@
Override
public
void
eat
(){
i
=
5
;
super
.
eat
();
System
.
out
.
println
(
"I eat bones."
);
}
}
__MACOSX/src/._Dog.java
src/InheritanceTest.java
src/InheritanceTest.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
@author
mrahman
*/
public
class
InheritanceTest
{
public
static
void
main
(
String
[]
args
)
{
Animal
animal
=
new
Animal
();
animal
.
eat
();
Dog
d
=
new
Dog
();
d
.
eat
();
d
.
run
();
Animal
a
;
// Compile-time association
a
=
new
Cat
();
// Runtime association
a
.
eat
();
// Polymorphism will decide which verion of eat method will be called.
//((Dog) a).run(); // it works only if a was actually pointing to a Dog object
}
}