abstract class

A

Afri

Hi

Please excuse the novice question.
The class I am trying to work with is defined as:
public abstract class WctpFactory
extends java.lang.Object

WctpFactory contains the following method:
public java.lang.String getTimestamp()

This is my program:

import java.io.*;
import com.arch.wctp.*;
public class wctpTime
{
public void main( String args[] )
{
String tStamp = WctpFactory.getTimestamp();
}
}

Compiling this produces the following error message:
wctpTime.java:16: non-static method getTimestamp() cannot be
referenced from a static context

What am I doing wrong?

Thanks
afri
 
C

Chris Smith

Afri said:
Please excuse the novice question.
The class I am trying to work with is defined as:
public abstract class WctpFactory
extends java.lang.Object

You need to find out how you're expected to obtain an instance of this
class. You can't just create one, because the class is abstract.
Typically, there will be a documented way to obtain such an object.
Perhaps you'll find a static method called getInstance() or something
like.

Once you've got a reference to an instance of the class (I'll call it
obj, for the sake of this example), you'd say "obj.getTimestamp()".

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
B

Bryce

Hi

Please excuse the novice question.
The class I am trying to work with is defined as:
public abstract class WctpFactory
extends java.lang.Object

WctpFactory contains the following method:
public java.lang.String getTimestamp()

This is my program:

import java.io.*;
import com.arch.wctp.*;
public class wctpTime
{
public void main( String args[] )
{
String tStamp = WctpFactory.getTimestamp();
}
}

Compiling this produces the following error message:
wctpTime.java:16: non-static method getTimestamp() cannot be
referenced from a static context

Your error has nothing to do with an Abstract Class.. It is because
you haven't instantiated the class WctpFactory and/or didn't declare
your method getTimestame() as a static method.

In other words, you can't access methods in a static context unless
you declare them as static.
 
A

Afri

Bryce said:
Hi

Please excuse the novice question.
The class I am trying to work with is defined as:
public abstract class WctpFactory
extends java.lang.Object

WctpFactory contains the following method:
public java.lang.String getTimestamp()

This is my program:

import java.io.*;
import com.arch.wctp.*;
public class wctpTime
{
public void main( String args[] )
{
String tStamp = WctpFactory.getTimestamp();
}
}

Compiling this produces the following error message:
wctpTime.java:16: non-static method getTimestamp() cannot be
referenced from a static context

Your error has nothing to do with an Abstract Class.. It is because
you haven't instantiated the class WctpFactory and/or didn't declare
your method getTimestame() as a static method.

In other words, you can't access methods in a static context unless
you declare them as static.
What am I doing wrong?

Thanks
afri

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top