定义一个时间类Time,类中有三个数据成员(Hour,Minute,Second)和两个成员函数(SetTime和PrintTime)。SetTi
展开全部
public class Time{
private int hour;
private int minute;
private int second;
public void setTime(int hour,int minute,int second){
this.hour=hour;
this.minute=minute;
this.second=second;
}
public void printTime(){
System.out.println("Now Time is:"+hour+"时"+minute+"分"+second+"秒");
}
}
private int hour;
private int minute;
private int second;
public void setTime(int hour,int minute,int second){
this.hour=hour;
this.minute=minute;
this.second=second;
}
public void printTime(){
System.out.println("Now Time is:"+hour+"时"+minute+"分"+second+"秒");
}
}
展开全部
public class Time
{
private string Hour;
private string Minute;
private string Second;
protected void SetTime()
{
}
protected void PrintTime()
{
}
}
{
private string Hour;
private string Minute;
private string Second;
protected void SetTime()
{
}
protected void PrintTime()
{
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一楼只定义私有成员变量,外部如何访问?这个类有何意义?二楼也类似。哥用C#3.0写一个
public class Time{
public int Hour { get; set; }
public int Minute { get; set; }
public int Second { get; set; }
public void setTime(DateTime dt)
{
this.Hour = Convert.ToInt32(dt.Hour);
this.Minute = Convert.ToInt32(dt.Minute);
this.Second = Convert.ToInt32(dt.Second);
}
public void printTime(){
System.out.println("Now Time is:"+hour+"时"+minute+"分"+second+"秒");
}
}
public class Time{
public int Hour { get; set; }
public int Minute { get; set; }
public int Second { get; set; }
public void setTime(DateTime dt)
{
this.Hour = Convert.ToInt32(dt.Hour);
this.Minute = Convert.ToInt32(dt.Minute);
this.Second = Convert.ToInt32(dt.Second);
}
public void printTime(){
System.out.println("Now Time is:"+hour+"时"+minute+"分"+second+"秒");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询