• Post Reply Bookmark Topic Watch Topic
  • New Topic

The program shows error while am using super keyword  RSS feed

 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//constructor
class Base
{

Base(int a)
{
System.out.println("in base"+a);;
}
}
class Cons extends Base
{
int b;
Cons()
{

this(msg());
System.out.println("in const"+b);

}
Cons(int a)
{
super(2);
this.b=a;

}

static int msg()
{

System.out.println("hi");
return 2;
}

public static void main(String...a)
{
Cons c=new Cons();
Base b=new Base();



}
}
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And your question is....?

I believe you've also been asked more than once to UseCodeTags (←click) when you post code. Learning HowToAskQuestionsOnJavaRanch is very important if you want people to help you, so please read both links carefully.

Winston
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also indent the code correctly, otherwise code tags will not help. We have some suggestions about indenting here.
 
Joren Uitzetter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're instantiating Base without an int as argument while you didn't declare a no-argument constructor for Base; hence it will not compile.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!