• Post Reply Bookmark Topic Watch Topic
  • New Topic

OOP Concepts  RSS feed

 
Girish Havaldar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How to demonstrate all OOPs concepts in a Singal Java program file.

Regards,

Girish
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basic OOP concepts are inheritance, encapsulation and polymorphism. To establish inheritance and polymorphism (without interfaces) you require two java classes. Try to read about the concepts and you can write them in one .java file.
 
Zeeshan Sheikh
Ranch Hand
Posts: 144
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
McGraw.Hill.Java.The.Complete.Reference.7th.Edition.Dec.2006 is really a good book for basic concepts. Author has done a tremondous job in explaining basic Java Concepts.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12562
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Girish Havaldar wrote:How to demonstrate all OOPs concepts in a Singal Java program file.

What do you consider "all" OOP concepts?

As with any program, the first step is to define your requirements. The above gives a loose idea, but is FAR from a spec...
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Girish Havaldar wrote:How to demonstrate all OOPs concepts in a Singal Java program file.

I suggest you start here. There may even be examples you can use.

Winston
 
Kotto Bass
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstraction and modularization are also OOP concepts, and all these can be done in one file (with multiple classes). I will attempt a basic explanation how each OOP concept is applicable. Consider an Employee class file Employee.java:



As you can see, it has private methods that are only accessible from an external class by using it's public methods. This demonstrates encapsulation (information hiding). Also notice how the code shows abstraction, with the Employee class made of variables illustrating its properties and methods illustrating behavior. If we want to double the salary, we have a specific method for that purpose only, showing modularization.

The non-public class 'Programmer' in the same file extends 'Employee' class showing inheritance. It is left on the reader to write an interface and demonstrate polymorphism.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zeeshan Sheikh wrote:McGraw.Hill.Java.The.Complete.Reference.7th.Edition.Dec.2006 is really a good book for basic concepts. Author has done a tremondous job in explaining basic Java Concepts.
If that is Herbert Schild, in my opinion that book moves too fast to be of use to beginners.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Zeeshan Sheikh wrote:McGraw.Hill.Java.The.Complete.Reference.7th.Edition.Dec.2006 is really a good book for basic concepts. Author has done a tremondous job in explaining basic Java Concepts.
If that is Herbert Schild, in my opinion that book moves too fast to be of use to beginners.


And though I haven't read it, I've heard Shildt's book is full of misinformation.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think misinformation is an exaggeration. It did have the errors I look for when I review a book eg about Scanner#nextLine() and the %n tag. I would have preferred to see OO concepts earlier in the book. Not a book I consider suitable for beginners, however, because of its fast pace.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!