• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java class Super()??

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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()?
 
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
super() always refers to the super class, if none other, it is Object class itself in java.
 
Vishnu Khera
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Harshvardhan thanks for your response

Oops... big goof up In elaborating my question properly I answered my own question
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Posts: 24
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Marshal
    Posts: 79153
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You’re welcome
     
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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 :



     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic