This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes the constructor(contain arguments) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "the constructor(contain arguments)" Watch "the constructor(contain arguments)" New topic

the constructor(contain arguments)

lang lang

Joined: Nov 01, 2003
Posts: 8
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{
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

Joined: Feb 05, 2003
Posts: 102
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".

David Crossett
-nothing important to say, but learnin' plenty-
lang lang

Joined: Nov 01, 2003
Posts: 8
in super(11),what the '11'represent?
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

It is the value you are passing to a method in the parent class.

Please ignore post, I have no idea what I am talking about.
I agree. Here's the link:
subject: the constructor(contain arguments)
Similar Threads
Doubt with overloaded super constructor
Inner Class inheritance super
constructor invocation