怎样在java中写一个类,调用可执行jar包。 代码怎么写?
展开全部
public class a{
public static void main(String[] args){
MeiNiv mn=new MeiNiv("丽丽",23,'女');
System.out.println(mn);
MeiNiv mn2=new MeiNiv("丽",23,'女');
System.out.println(mn.equals(mn2));
methold(mn2);
}
public static void methold(Object obj){
if(obj instanceof MeiNiv){
MeiNiv mv=(MeiNiv)obj;
mv.Say();
}
}
}
class MeiNiv{
String name;
int age;
char sex;
public MeiNiv(String name,int age,char sex){
this.name=name;
this.age=age;
this.sex=sex;
}
public String toString(){
return "name:"+name+",age:"+age+",sex:"+sex;
}
public void Say(){
System.out.println("我要毕业了");
}
public boolean equals( Object obj){
//表示同一个对象
if(this==obj){
return true;
}
//对每一个属性进行比较
if(obj instanceof MeiNiv){
MeiNiv mv=(MeiNiv)obj;
if(this.name!=mv.name){
return false;
}else if(this.age!=mv.age){
return false;
}else if(this.sex!=mv.sex){
return false;
}else{
return true;
}
}else{
return false;
}
}
}
public static void main(String[] args){
MeiNiv mn=new MeiNiv("丽丽",23,'女');
System.out.println(mn);
MeiNiv mn2=new MeiNiv("丽",23,'女');
System.out.println(mn.equals(mn2));
methold(mn2);
}
public static void methold(Object obj){
if(obj instanceof MeiNiv){
MeiNiv mv=(MeiNiv)obj;
mv.Say();
}
}
}
class MeiNiv{
String name;
int age;
char sex;
public MeiNiv(String name,int age,char sex){
this.name=name;
this.age=age;
this.sex=sex;
}
public String toString(){
return "name:"+name+",age:"+age+",sex:"+sex;
}
public void Say(){
System.out.println("我要毕业了");
}
public boolean equals( Object obj){
//表示同一个对象
if(this==obj){
return true;
}
//对每一个属性进行比较
if(obj instanceof MeiNiv){
MeiNiv mv=(MeiNiv)obj;
if(this.name!=mv.name){
return false;
}else if(this.age!=mv.age){
return false;
}else if(this.sex!=mv.sex){
return false;
}else{
return true;
}
}else{
return false;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询