i currently studying oop in java and i read in a book that java swing jframes are good to understand how oop works in creating gui's in a java program,so where are the following mostly implemeted.
I have done some research and i found some oop concepts implemeting in java
Inheritance - obviously a class need to inherit javax.swing.jframe to use all the methods.
Encapsulation - after creating buttons,panels e.t.c all of them have private access modifiers
So where are
- Association &Aggregation
- Polymorphism
- Abstraction & Interface
utilised?
Answer
Aggregation - JFrame has a JPanel
Composition - JFrame has a JButton
(composition because JButton cannot exist without a frame)Polymorphism - Sometimes parameters are passed to methods which are asking in more generic way for example
someMethod(Component comp)
for comp we can pass a JButton (Because JButton IS-A Component)Abstraction/Interface sometimes it is needed to implement interfaces and abstract classes, there you have to override all the abstract methods.
No comments:
Post a Comment