aspose file tools*
The moose likes Beginning Java and the fly likes Java class Super()?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java class Super()??" Watch "Java class Super()??" New topic
Author

Java class Super()??

Vishnu Khera
Greenhorn

Joined: Nov 29, 2008
Posts: 24
I was trying out some code and came across unexpected behavior as and referenced my user defined class to 'new Super()'. Is there any predefined class in Java API by the name Super()?
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

super() always refers to the super class, if none other, it is Object class itself in java.
Vishnu Khera
Greenhorn

Joined: Nov 29, 2008
Posts: 24
Harshvardhan thanks for your response

Oops... big goof up In elaborating my question properly I answered my own question
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

Super != super.

I'm not aware of any pre-defined classes with that name (and it would be a poor choice of name so I'd be surprised if there was). And unless it was in java.lang you wouldn't have a clash anyway unless you imported it.

So if the capitalization is as you say, the cause of the strange behaviour is probably something else.
Vishnu Khera
Greenhorn

Joined: Nov 29, 2008
Posts: 24
Matthew, thanks for your response

Very true, it would be a poor choice of a class name. I searched for 'Super()' in google and Java API but could not find any class by this name
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39435
    
  28
As Matthew has already hinted, spellings are important in programming. In a case‑sensitive language like Java, the compiler will distinguish
  • super, which is a keyword, from
  • Super, which is a poorly‑named class, and both of those from
  • Super() which is (probably) a constructor call.
  • You should use whichever spelling is correct in your posts. You probably sought Super in the index not Super().
    Vishnu Khera
    Greenhorn

    Joined: Nov 29, 2008
    Posts: 24
    Campbell thanks for the clarification

    It was indeed a poor choice of naming my class as Super, but the reason for naming it so was the length of the program I wanted to compile. It was a small 10 line program.

    Yes, its a good tip because I was getting a strange compile time error in the same program

    I understand if there were any, it would be class Super and not class Super()

    Probably waaay too excited to post questions on this forum and get suuuper quick replies


    BIG THANKS TO ALL OF YOU
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39435
        
      28
    You’re welcome
    vinay chaturvedi
    Greenhorn

    Joined: Jan 16, 2012
    Posts: 14
    You can use super as a keyword to call the super class methods in a sub-class.

    For Ex : super.superClassMethod();

    Or you can use super() to call the super class constructor.

    For Ex :



     
     
    subject: Java class Super()??