• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

help me in kicking off the bug from the following code

 
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 ());
}
}
 
author
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?
 
author
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
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:
 
Fire me boy! Cool, soothing, shameless self promotion:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic