This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the constructor(contain arguments)

 
lang lang
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yesterday I saw a code ,I have something to ask,hope to help me ,thank you!
The code is as follows:
class Game{
Game(int i){
System.out.println("Game constructor");
}
}
class BoardGame extends Game{
BoardGame(int i){
supper(i); //what does super mean,how to use it,if we can not write it here.
System.out.println("BoardGame constructor");
}
}
public class Chess extends BoardGame{
Chess(){
super(11);//the argument'11'here which I am confused about
System.out.println("Chess constructor");
}
public static void main(String[] args){
Chess x=new Chess();
}
}///:-
 
David Crossett
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using 'super', you MUST place it in your definition BEFORE anything else... in your example, the super() must go above the line of code it is currently under. What 'super' does is call the default constructor of the class that it inhereted from (hence, it must be the first call made - to create the object). Sometimes 'super' will have arguments, sometimes not. For example,

In the above code, the call to 'super' is a call to the JFrame class, and constructs a framed window with the title "Digital Clock".
 
lang lang
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in super(11),what the '11'represent?
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is the value you are passing to a method in the parent class.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic