• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

difficult to understand oops

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well friend i think it is very simple question to many of u..

but my concept about opps is not clear even then i can create a good project on java...
but the basic thing that i want to understand the concept of oops which is very essential for any developer..

i want to know how can we conclude that this thing (particular any thing) is going to be a class or object..

one thing more what is the existence of "ourself" in this world?

are we a object or a class..

please help me out so that i can understand the oops concept.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anant Dixit wrote:
but my concept about opps is not clear even then i can create a good project on java...



i dont believe . we are an Objects . what do you think?
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Anant Dixit !
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello and welcome to the Ranch.

In OOP terms, everything "can be" an object. A class is just a representation of the object. If you have done a bit Java projects then you should at least know the concepts of OOP such as encapsulation, inheritance and polymorphism.

IMHO the primary purpose of OOP is reuse. You may want to look through the Java tutorials on OOP here
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anant Dixit wrote:well friend i think it is very simple question to many of u..

but my concept about opps is not clear even then i can create a good project on java...
but the basic thing that i want to understand the concept of oops which is very essential for any developer..



Yes, indeed you are very right and in a proper path towards learning the basics! Appreciate that!


i want to know how can we conclude that this thing (particular any thing) is going to be a class or object..



There is a *big* difference between the two. Class is a template or blueprint with which the objects are prepared. You can take Class as an showpiece or model and the object is the *real product*.

The other difference is, "object" is a 'real', 'live' entity with manageable properties and methods to operate upon!


one thing more what is the existence of "ourself" in this world?

are we a object or a class..



I just read it as a single line (only first line) and got confused what to say? lol!!

We would be the 'object' of the 'Person' class! -- does it make sense?

 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote: A class is just a representation of the object.



Not true! A class is a template or a bare bone structure based on which the objects are made. You can even call it as a rough figure!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the following analogy: A class is a blueprint to make objects. For example, suppose you have a class House. The class House is the blueprint that explains exactly how to make a specific House object.

Your own house, or your sister's house, are instances of class House - they are the concrete House objects that are made using the blueprint.

So, a class is like a recipe, or a set of instructions, or a plan, that explains how to make a specific kind of object.

See Trail: Learning the Java Language in Sun's Java Tutorials. There are lessons there about object-oriented programming concepts and classes and objects.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, adding on top of Jesper's explanation, you can think of a class as a 'Reference' for making the 'real' objects!

Every time you look at the reference/guide before you create an object in existence as it serves you the basic information of

1. What actually constitutes an object? Other way, what will the object be having with it? If it is a House object, it would be having doors, windows etc., If it is a Person object, it would be having eyes,ears, nose etc., -- They are called as 'members' of the class (or an object really)

2. They also convey the quantity/volume -- how many doors, windows a 'house' object should have? --- represented by the 'datatypes' like String, int etc.,

3. What are the objects supposed to do? -- In case of a house object, it does NOT seem to do any real activity except staying/lying as it is. But in case of a person object, it is supposed to do many actions like 'breathe()', 'eat()', 'sleep()', 'speak()', 'run()' etc., --- they are called as 'methods' or 'behaviors'.

All these information are present in the class. So you look at your 'class' or the 'reference' or 'template' or a 'blueprint' each time before you create an object.

Moreover, being a 'reference' a class does NOT exist in reality whereas an 'object' is the one which is existing in reality. It is alive!!

Does it help?
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anant Dixit wrote:
one thing more what is the existence of "ourself" in this world?

are we a object or a class..



A class is a type definition and from it one can create many objects of that type. Say you want to define a type called Human. In its simplest form it would look like this,

class Human {
}

From it you could create objects like,

Human me = new Human();
Human you = new Human();
Human someoneElse = new Human();
 
Marshal
Posts: 79938
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Anant Dixit wrote:well friend i think it is very simple question to many of u..

. . .

It obviously isn't a simple question to you; I hope the answers here have been helpful.

But please avoid that sort of abbreviation (u); as explained here, that can cause confusion.
 
Anant Dixit
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for all of you...

actually you all guys really encourages me coz i think i just asked a very simple question and no one will give me reply..

NOW COME TO THE POINT.

whatever you told me i am accepting..
but one question again come to my mind "What is the existence of ourself in this world?"
as many of you told that we are a object of a human class i also accepted it but now i have a question which really make me thinking again that are we really an object or a class?

class LivingBeing
{

}

class Human extends LivingBeing
{
abstract wayoftalking()
{
}

abstract personality()
{
}

}

class Male extends Human
{

}


now question arises how can we further inherit these class?

coz if i am an object then i should have a object of Male class right?

object Anant=new Male();

but here my question arises if i have a method the wayoftalking(), personality()

then every person has a unique wayoftalking(),personality() so where should i impliment this method?

because the personality of mine is completely unique and no one has that personality.

thats why i m thinking that we are a class.

means

class Anant extends male
{
}

now here i can implement this methods

please help me out from this confusion.
 
Embla Tingeling
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anant Dixit wrote:
but one question again come to my mind "What is the existence of ourself in this world?"
as many of you told that we are a object of a human class i also accepted it but now i have a question which really make me thinking again that are we really an object or a class?



Java doesn't give you any answers to design questions. It cannot tell you "What is the existence of ourself in this world?". The answer to that question is NOT somehow hidden within the Java language. It's up to you to find the answer and tell Java. You're the designer. You're the programmer.

Java just makes available programming language elements. One is the ability to create your own types using class, enum and interface. Another is the ability to create objects from concrete types. Once you've come up with the "The existence of ourself in this world" design, you go ahead and implement it in Java using the features Java puts at your disposal.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anant Dixit wrote:...


now question arises how can we further inherit these class?
...
but here my question arises if i have a method the wayoftalking(), personality()

then every person has a unique wayoftalking(),personality() so where should i impliment this method?



Well, here I would look at the key word "every person has a ..." The word 'has' leads to a special relationship. First thing to notice that if an Object HAS something, that something is probably a Thing (and therefore should be an Object). Methods are usually used to perform actions, while Object are used to model Things. And so having a method called personality() probably doesn't make sense. Rather, you should have a Class called Personality (made up of parts which can be used to describe an individual's personality). Then each person might have a Personality Object:


This pushes the problem of 'every person has a unique personality' question out of the Human class and into the Personality class. Now you have to ask the question 'What is a personality' (see the link above) and develop a class which can capture the characteristics of the personality by definition but also capture the uniqueness by varying the components or parts of the Personality.
 
Anant Dixit
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Steve

your explanation really help me to understand the misconception that i had.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well,
let me leave the philosophical aspect and jump to coding.....

This is wrong (at least the compiler would say so..)


1. Human has a few abstract methods, so it should be an abstract class and the methods, they do not need to be defined at all
2. If Male extends Human then
a. Male should either provide implementations for those methods OR
b. Itself be called abstract.

I would Personally favor the second option above (viz 2 > a )

So,

When you say:


or let me state that a bit better:



it would still not compile unless you write:



IF Male was not abstract,

The above Code would still work and It would still prefer Anant's style of walking and Anant's Personality since it overides its Parent

So yes, Java does not provide all the solutions to Live (else i would have had 1000 Girlfriends)

But It does tell you the rules
Man the compiler is strict !!
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing about Java that I had once found a lot confusing at beginning and i feel like sharing:

Pardon my analogy

[Edit: changed to lower caps]

The child is more powerful than the parent
because:
1. He has his own abilities
2. And he has his parent's abilities too

 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:... CHILD ... PARENT ...


It is really confusing to think of a superclass as the "parent" and a subclass as the "child", because inheritance in object oriented programming has a totally different meaning than inheritance in biology. Using terms such as "parent class" and "child class" confuses the two and makes it harder to understand what inheritance in object oriented programming means.

Inheritance in OOP means specialization - a subclass is a specialized version of a superclass. Inheritance also implies that there is an is a relationship between the subclass and the superclass - an instance of the subclass is a (specialized version of) an instance of the superclass.

For example, a Male is a specific kind of Human, so it makes sense to make Male a subclass of Human. Note that a Male is a Human.

This doesn't hold for the words "parent" and "child" - a child is not a parent, and it's certainly not a specialized kind of parent.
 
Campbell Ritchie
Marshal
Posts: 79938
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Salvin Francis, please look at this FAQ.
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Salvin Francis, please look at this FAQ.


sorry, i edited the post now.
 
Campbell Ritchie
Marshal
Posts: 79938
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apology accepted and thank you
 
Anant Dixit
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:




so when you create a object anant at a same time you implement both the method along with this object.
it means that now Male class is not abstract coz as both the method are implemented here.
but if a also create an object in the same class like


and here i do not implement the methods.

this code is compile coz now Male class already implement both the method

and now if i called the method


then as i think it will show the wayoftalking of anant?

so is it right?
 
Campbell Ritchie
Marshal
Posts: 79938
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have already asked you to avoid abbreviations Anant Dixit; many people who didn't grow up speaking English may not know what "coz" means.
 
Anant Dixit
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I have already asked you to avoid abbreviations Anant Dixit; many people who didn't grow up speaking English may not know what "coz" means.



sorry i will keep this in mind... and try to avoid these words....
 
Campbell Ritchie
Marshal
Posts: 79938
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apology accepted
 
You got style baby! More than this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic