• 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
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

can we have class name as return types in functions in java

 
Ranch Hand
Posts: 66
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can we have class name as return types in functions in java ?



what is the use?? we don't have like this option in c++ ??
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can.

In C++, you'd probably return a pointer to a Bicycle. The Java version returns a reference to a Bicycle object, which is very similar, really.
 
Greenhorn
Posts: 23
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Yes, This returns the whole object fastest to the caller....

Something like,



and the fastest will contain reference to myBike or yourBike, whichever is returned.


One Advice: Java is different in C++ from many aspects,
Just carry on with the fundamentals of OOP and dive into Java as a new language. Otherwise it can confuse you like anything!!
 
Marshal
Posts: 80781
489
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tejas Shah wrote: . . . This returns the whole object . . .

Not quite. It returns a value which is the same as the memory location of that object. It does not actually return the whole object.

One Advice: Java is different in C++ from many aspects, . . .

Very wise advice. Lots of people think Java™ and C++ are versions of the same language and get very confused about it.
 
Tejas Shah
Greenhorn
Posts: 23
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree.
Java never passes the objects, but the reference.

As there is nothing like a pointer in Java, this is just an internally handled and we can access the same object at the caller. To be precise, suppose, 'myBike' is faster, 'fastest' and and 'mybike' will refer to the same object. and changes made to either of these will be reflected in each other... it's like having two tags atached to the same things.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
or two remote controls controlling the same car
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David O'Meara wrote:or two remote controls controlling the same car


I just love the idea of a remote control cat! Where can I get one?
 
Campbell Ritchie
Marshal
Posts: 80781
489
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All cats work by remote control. Only the cat does the controlling . . .
 
Tejas Shah
Greenhorn
Posts: 23
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cat... ???

It was car we ware talking about. Anyways, I'm also interested in Remote Control Cat, if exists!!

- Tejas
SCJP 6

Cherish your life..!!
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tejas Shah wrote:Cat... ???


The link David posted talks about cats.

I apologise for taking this off topic, though. I'll shut up now.
 
Campbell Ritchie
Marshal
Posts: 80781
489
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tejas Shah wrote:Cat... ???

It was car we ware talking about. . . .

But that doesn't stop us taking the discussion off-topic
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic