In: Computer Science
Write a Java code to represent a
1. Date class. As date class is composed of three attributes, namely month, year and day; so the class contains three Data Members, and one method called displayDate() which will print these data members.
Date |
month : String year: int day : int |
displayDate(): void |
public class Date {
int year;
String month;
int day;
void displayDate()
{
System.out.println("Date :
"+month+" "+day+","+year);
}
}
public class DateDemo {
public static void main(String[] args)
{
Date obj=new Date();
obj.day=31;
obj.month="December";
obj.year=2012;
Date obj1=new Date();
obj1.day=4;
obj1.month="july";
obj1.year=1776;
obj.displayDate();
obj1.displayDate();
}
}