Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help me out with this program

 
Shyam Sunder V R
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please tell me the output of this program?

code:
--------------------------------------------------------------------------------


class Ace{

public void run(){
System.out.println("ace run");
}

}
public class TestSuper extends Ace {
public void test(){
System.out.println(super.getClass()+"");
System.out.println(this.getClass().getName());
}
public static void main(String[] args) {
TestSuper testit=new TestSuper();
testit.test();
}
}


--------------------------------------------------------------------------------

Also please suggest whta are the instances when SUPER keyword is used...
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shyam Sunder V R:
Can you please tell me the output of this program?


Have you tried running it yourself? What did you observe?

Also please suggest whta are the instances when SUPER keyword is used...


Sounds like an assignment/homework.
http://faq.javaranch.com/java/DoYourOwnHomework
[ August 08, 2008: Message edited by: Maneesh Godbole ]
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shyam Sunder V R:

Also please suggest whta are the instances when SUPER keyword is used...


When you want an immediate reference to your parent class !
 
Shyam Sunder V R
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have run this program and this is the output I get


Class TestSuper
TestSuper

I had thought that I should have got
Ace
TestSuper
since I am using SUPERkeyword I should have got "Ace" as output for super.getClass() but I get TestSuper

this is my doubt....!
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are confusing between the method invocation of a super class and the super.getClass().
For the API docs (emphasis added)
Returns the runtime class of this Object


Runtime class in your case is TestSuper as you have


Even if you change it to
you will still end up with the same result as the object created is of type TestSuper

To demonstrate the difference I am talking about, run the following code and observe the output.

 
Shyam Sunder V R
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what you have done here is something I know in usual about SUPER and have tested it and that was basically the reason i had asked regarding this.

Can you give the link for the API docs where your quote is specified???
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shyam Sunder V R:

Can you give the link for the API docs where your quote is specified???


http://java.sun.com/javase/6/docs/api/java/lang/Object.html#getClass()
These are the same standard java docs which you usually download from the java site Http://www.java.sun.com
 
Shyam Sunder V R
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Maneesh
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic