Week 011 B
Week 011 B
Week 011 B
Abdul-Rahman Mahmood
Assistant Professor, Computer Science, FAST-NU
abdulrahman@nu.edu.pk reddit.com/user/alphapeeler
alphapeeler.sf.net/pubkeys/pkey.htm www.flickr.com/alphapeeler
pk.linkedin.com/in/armahmood http://alphapeeler.tumblr.com
bqb-tsid-asp armahmood786@jabber.org
alphapeeler alphapeeler@aim.com
alphapeeler abdulmahmood-sss
armahmood786 alphapeeler@icloud.com
http://alphapeeler.sf.net/ pinterest.com/alphapeeler
Downloads
https://eclipse.dev/papyrus/
https://ftp.yz.yamagata-
u.ac.jp/pub/eclipse//modeling/mdt/papyrus/rcp/2024
-06/6.7.0/papyrus-2024-06-6.7.0-win64.zip
https://www.eclipse.org/downloads/packages/release/
kepler/sr1/eclipse-ide-java-developers (OPTIONAL)
Abstraction
abstract class Animal {
// abstract methods
abstract void move();
abstract void eat();
// concrete method
void label() {
System.out.println("Animal's data:");
}
}
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation
problem:
The method displayDetails() from the type Animal04 is not visible
at w01ex03Encapsulation.ElectronicItem.main(ElectronicItem.java:11)
Inheritance
class Bird {
public String reproduction = "egg";
public String outerCovering = "feather";
public void flyUp() {
System.out.println("Flying up...");
}
public void flyDown() {
System.out.println("Flying down...");
}
}
Reproduction: egg
Outer covering: feather
Flying up...
Flying down...
Polymorphism - Static
(method overloading)
class Bird {
public void fly() {
System.out.println("The bird is flying.");
}
public void fly(int height) {
System.out.println("The bird is flying " + height + " feet high.");
}
public void fly(String name, int height) {
System.out.println("The " + name + " is flying " + height + " feet
high.");
} Output:
} The bird is flying.
The bird is flying 10000 feet high.
The eagle is flying 10000 feet high.
public class TestBirdStatic {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Static polymorphism (method overloading)
Bird myBird = new Bird();
myBird.fly();
myBird.fly(10000);
myBird.fly("eagle", 10000);
}
}
Polymorphism - Dynamic / Runtime
(method overloading)
public class Animal {
public void eat() {
System.out.println("This animal eats insects.");
}
}