- 2
What is OOP and explain with example?
I want to know about OOP.
2 Réponses
+ 3
We are human. Humans are animal. Animals are biological. Biologicals are object. Finally, all the things in the world are "Object".
For Java, we can explain it as...
public class Human extends Animal {
public void talk ( ) {
System.out.println ( "say hello." ) ;
}
public void think ( ) {
System.out.println ( "I'm thinking." ) ;
}
}
public class Animals extends Biological {
public void eat ( ) {
System.out.println ( "I'm eating" ) ;
}
}
public class Biological {
// public class Biological extends Object {
/* All the classes is derived class of Object
** So extends Object is not necessary */
public Biological breed ( ) {
return new Biological ( ) ;
}
}
The Human inherits the Animal and Biological.
So the Human have the methods talk, think, eat, breed.
The above is the basic concept of OOP.