I want to access the protected methods mentioned in an abstract class how can i do that? For example: in java.util.Calendar there is a protected method getTimeInMills(). How can retrieve the value. In my class a.java i want to call the calendar class as Calendar cal = Calendar.getInstance(); System.out.println(cal.getTimeInMills()) ----> this line is giving compilation error saying getTimeInMillis() is a protected method. How can i access this??
hmm.. you are accessing the getTimeInMillis() method directly from the superclass, wich is not valid. Accessing a protected method is valid through inheritance only. So try to create a class that inherits from Calendar (I don't know whether Calendar is final, I'll have to check that) and use your class to access getTimeInMillis. This is just the first thing that comes to my mind, but the point here is that protected methods must be accessed by inheritance only. let me know how it goes. [ July 23, 2003: Message edited by: Andres Gonzalez ]
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Thank you. Here my restriction(in project) is to use jdk1.3.1. So i will use getTime of java.util.Date. One more question . If i want to represent current system date and time like yyyymmddhhmmss ie., 20030722142434 How i can achieve conveniently. Right now i am doing like this: Stringbuffer sb = new StringBuffer(); sb.append(calendar.get(calendar.YEAR)); sb.append(calendar.get(calendar.MONTH)); ...... . ... ... and finally using sb.toString() to get the value. Is there any better way?? Thanks in advance for your help kiran
Here is what I came up with to print (without saving to a String) the current date/time. You need to import java.util.Date (to get the current date) and java.text.SimpleDateFormat (to define the display format). System.out.println(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())); Hope that helps. Ross
posted 16 years ago
I should add that what I wrote is from jdk 1.4, but from what I recall reading, it was defined in 1.3.1, I believe....not certain of that though. Ross