This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes returntypes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "returntypes" Watch "returntypes" New topic
Author

returntypes

Ramgopal Reddy
Greenhorn

Joined: Jan 28, 2006
Posts: 22
in this aplication whats going exactly i dont know. As per my knowledge front of methods we put returntypes but below aplication Test acts as (?)



class Test {

int a;

Test(int i) {

a = i;

}

Test incrByTen() {

Test temp = new Test(a+10);

return temp;

}

}

class RetOb {

public static void main(String args[]) {

Test ob1 = new Test(2);

Test ob2;

ob2 = ob1.incrByTen();

System.out.println("ob1.a: " + ob1.a);

System.out.println("ob2.a: " + ob2.a);

ob2 = ob2.incrByTen();

System.out.println("ob2.a after second increase: "

+ ob2.a);

}

}


Ram's
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Ramgopal Reddy:
... As per my knowledge front of methods we put returntypes but below aplication Test acts as (?)...

...a constructor, which does not have a return type.

For details on constructors, see this section from Bruce Eckel's Thinking in Java.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Abhinav Gogna
Greenhorn

Joined: Oct 23, 2005
Posts: 20


This is a constructor.




This is a method with the [B] Test object [/B} return type. Java is oo language and you can return objects as well as primitives.

Capisce
Abhinav Gogna
Greenhorn

Joined: Oct 23, 2005
Posts: 20


This is a constructor.




This is a method with the [B] Test object [/B} return type. Java is oo language and you can return objects as well as primitives.

Capisce
 
GeeCON Prague 2014
 
subject: returntypes