Java static静态变量 C语言文件读写
1.
(1)
public class test1 { public static void main(String[] args) { javabean1.teachername="jianjun";//直接在类调用,方便一点点 javabean1 s1 = new javabean1(); s1.setName("liujiawei"); s1.setAge(18); s1.setGender("男"); s1.study(); s1.show(); System.out.println(); javabean1 s2=new javabean1(); s2.setName("fanwenshuo"); s2.setAge(18); s2.setGender("女"); s2.study(); s2.show(); } }
(2)
public class javabean1 { String name; int age; String gender; public static String teachername; public javabean1() { } public javabean1(String name, int age, String gender) { this.name = name; this.age = age; this.gender = gender; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } //行为 public void study(){ System.out.println(name+"正在学习"); } public void show(){ System.out.println(name+","+age+","+gender+","+teachername); } }
2.
int main(void)
{
FILE* fp;
fp = fopen("b.txt", "r+");
if (fp == NULL)
{
printf("b.tet文件打开失败!\n");
}
else
{
printf("b.txt文件打开成功\n");
ch = fgetc(fp);
while (!feof(fp))
{
printf("读出来的字符:%c\n", ch);
ch = fgetc(fp);
}
fclose(fp);
}
return 0;
}