Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructor

 
radhika ayirala
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class test
{
public static void main( String [] args )
{
new test();
}
test()
{
test(2);
}
test(int x)
{
System.out.println(x);
}
}


why is this giving an error?
 
Chang Tzu-yu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call Constructor must use "this(2)"
public class test {
public static void main(String[] args) {
new test();
}

test() {
this(2);
}

test(int x) {
System.out.println(x);
}
}
 
radhika ayirala
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
chandraiah chintakayalu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when your calling a super constructor it should be called as:
super(2);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic