aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Please help me out with this program 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 "Please help me out with this program" Watch "Please help me out with this program" New topic
Author

Please help me out with this program

Shyam Sunder V R
Greenhorn

Joined: Jul 29, 2008
Posts: 20
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

Joined: Jul 26, 2007
Posts: 10376
    
    8

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 ]

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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 !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Shyam Sunder V R
Greenhorn

Joined: Jul 29, 2008
Posts: 20
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

Joined: Jul 26, 2007
Posts: 10376
    
    8

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

Joined: Jul 29, 2008
Posts: 20
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

Joined: Jul 26, 2007
Posts: 10376
    
    8

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

Joined: Jul 29, 2008
Posts: 20
Thank you Maneesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help me out with this program