Java简单逻辑运算以及static与new对象实验

public class Helloworld {
static int e =6;
public static void main(String[] args) {
boolean a =true;
boolean b =false;
System.out.println("a&&b:"+(a&&b));//a与b a&&b:false
System.out.println("a||b:"+(a||b));//a并b a||b:true
System.out.println("!(a&&b):"+!(a&&b));//a与b取非 !(a&&b):true
int c =5;
boolean d =(c<4)&&(++c>6);
System.out.println(c); // 5
System.out.println(d); // false
/* =========================================================
=========================================================*/

Helloworld a1=new Helloworld(); //建立类a1
Helloworld b1=new Helloworld(); //建立类b1
Helloworld c1=new Helloworld(); //建立类c1
System.out.println(a1); //输出"Helloworld@4554617c"(储存地址)
System.out.println(b1); //输出"Helloworld@74a14482"(储存地址)
a1.e=7; //在al中调用e,并定义其为7
System.out.println(a1.e); //输出结果为7
System.out.println(b1.e); //输出结果为7
System.out.println(c1.e); //输出结果为7

/*=============================================================================下方代码为实验new+对象与static的作用而写的实验性代码,无实际意义 ==============================================================================*/

/* String[] a3={"abcd"};
a1.main(a3);无意义代码*/
}
public void asd(String[] args) {
ABCD jkh= new ABCD();
String[] a3={"abcd"};
jkh.al (a3);
ABCD.al (a3);
jkh.sdf (a3);
ABCD.sdf(a3); //(报错)
}
}
class ABCD{
public static void al(String[] args) {
}
public void sdf(String[] args) {
}
}
该实验得到效果为:
static在一个项目中定义的方法(主要main,该实验中有asd、al、sdf)可以被对象以及类调用,如果没有static则可以被类调用,却不能被对象调用。

posted @ 2021-12-12 20:39  小凡的博客  阅读(126)  评论(0)    收藏  举报