File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

returntypes

 
Ramgopal Reddy
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);

}

}
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhinav Gogna
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic