This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help me in kicking off the bug from the following code

 
Akshay Kumar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while compiling the following code, an error occurs and what could b the soln to resolve this code. thanx.
abstract class second {
int i;
abstract void setValue (int);
int getValue () {
return i;
}
abstract void printValue ();
}
public class first extends second {
static first f = new first();
public first() {
}
static public void main(String[] args) {
System.out.println("Hello");
f.setValue (10);
f.printValue();
}
void setValue (int iValue) {
i = iValue;
}
void printValue () {
System.out.println("Value of i ::: " + f.getValue ());
}
}
 
David Peterson
author
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. What is the error?
2. What do you think the problem is?
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I received these errors:

when I compiled the program.
Suggestions/questions:
* post in the beginner's forum next time
* what do you think "<identifier> expected" means?
* format your code to make it easier to follow. Start by reading Sun's coding conventions at http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html. For example, the class names should be First and Second, not first and second.
* when posting code here, use the appropriate code tags
The fix to get the code to compile is very simple. Hint: the method signature is missing something. Good luck.
Jeff
[ March 11, 2004: Message edited by: Jeff Langr ]
 
Akshay Kumar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx for the response.
can't i specify the parameter's type alone, as a part of the signature. why shld i also give some identifier to it?
in C or C++, the parameter's type in the declaration is suufice but why it is not in java?
 
David Peterson
author
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question. It helps to document the method if you give descriptive variable names in the abstract class. E.g. compare these two declarations:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic