• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

relationship between abstract and inheriance class

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THe abstract classes can have constructor ?
public abstract class Student
{
int[] id;
public Student(int length)
{
id = new int[length];
}
// abstract methods.
}
if I want a its subclass of Student to call super(), it does not work. Can anyone help me little.
public class SubStudent extends Student
{
public SubStudent()
{
super(4);
}
}
I got error like:
SubStudent.java: cannot resolve symbol
symbol : constructor Student ()
location: class Student
{
^
1 error
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use jdk1.3, use jdk1.2.
I do not get this error with my jdk version.
Chris
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Although the original intention of construction abstract class is to give a outline for follow up development, but you can implement it like other normal class. For respect the keyword "abstract", you can't use "new" operator. I try the following program, it works well. I use JDK1.3.
abstract class Student
{
int[] id;
public Student(int length)
{
id = new int[length];
}
// abstract methods.
}
public class SubStudent extends Student {
public SubStudent() {
super(4);
}
public static void main(String[] args) {
SubStudent ss = new SubStudent();
System.out.println(ss.id[0]);
}
}
I hope it will help you.
kevin jia
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ldcai- your code compiles fine for me using JDK 1.3. What line number does your compiler object to exactly? You write that it objects to the Student() constructor, but there is no Student() constructor anywhere in the code. I suspect you have a typo somewhere.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I compiled with JDK1.2.2. It compiles fine. Also I could not see any error just by browsing the code also.
regds
maha anna
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic