Solved

How to avoid this messsage (Static Issues)

Posted on 2004-08-17
5
327 Views
Last Modified: 2010-03-31
This is my code:

program A:
========
...
...
public static synchronized Date getToday()
  {      
        return new Date();
   }
..
..


trying to access from here..

Program B:
=======
...
...
piObj.getContmstr().setInituwrtdt(new DateUtil().getToday());
...
...


And my "warning" message is this :

The static method getToday() from the type DateUtil should be accessed in a static way.


Question
=====
How can i resovel this issues?

ThankYou.



0
Comment
Question by:acl6804
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:pat5star
ID: 11827486
I'm assuming program A is a class called DateUtil. If so, you can call it like this:

piObj.getContmstr().setInituwrtdt(DateUtil.getToday());

You do not need to use the 'new' keyword when calling a static method. You just use the class name and the method you are calling.

Hope that helps,

-Pat
0
 

Author Comment

by:acl6804
ID: 11828579
but if i remove the "new" in the line, i will haev this problem.

"The method DateUtil() is undefined for the type PropInputServlet

** PropInputServlet is the name of my program B.

0
 
LVL 3

Accepted Solution

by:
pat5star earned 250 total points
ID: 11828911
Make sure your not writing it as DateUtil().getToday(), it should be DateUtil.getToday(). Also, are you importing your 2nd class? If the class is called DateUtil and is in your package my.package.DateUtil then you need to import it at the top of your page like this:

import my.package.DateUtil;

-Pat
0
 

Author Comment

by:acl6804
ID: 11837851
oh.. no wonder.. pat5star, can tell me what happend?

static means no need "new"??
0
 
LVL 3

Expert Comment

by:pat5star
ID: 11838127
"static means no need "new"??"

Your right. Static methods or fields are like global variables or functions. You only use the "new" keyword when you are creating a new object.

-Pat
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now