本人大三,学习方向是嵌入式,该死的学校竟然开了java程序设计教程。
有几题改错题求解答,谢谢class Person
{ static int count=0;
protected String name; protected int age;
public Person(String n1,int a1)
{ name = n1; age = a1; this.count++; }
}
public class Student extends Person
{ static int count=0;
protected String dept;
protected Student(String n1,int a1,String d1)
{dept = d1;
this.count++;
}
public static void main(String args[])
{ Person p1 = new Person("王小明",21) ;
p1.print();
Student s1 = new Student(‘陈小瑞’,19,‘计算机系’);
s1.print();
}
}public class Test1{
float f=3.14;
char c=’中’;
boolean b=”false”;
int i;
void f(int a){
i=a;
}
public void main(){
Test1 t=new Test1();
a=5;
t.f(a);
}
public class Father{
protected int i;
String j;
private int k;
public int m;
}
import folder1.Father;
public class Son extends Father{
public static void main(String[] args){
Son s=new Son();
s.i=1; s.j=”abc”; s.k=2; s.m=3;
}
}//其中Father放在folder1包内,Son放在folder2包内;
程序改错
有几题改错题求解答,谢谢class Person
{ static int count=0;
protected String name; protected int age;
public Person(String n1,int a1)
{ name = n1; age = a1; this.count++; }
}
public class Student extends Person
{ static int count=0;
protected String dept;
protected Student(String n1,int a1,String d1)
{dept = d1;
this.count++;
}
public static void main(String args[])
{ Person p1 = new Person("王小明",21) ;
p1.print();
Student s1 = new Student(‘陈小瑞’,19,‘计算机系’);
s1.print();
}
}public class Test1{
float f=3.14;
char c=’中’;
boolean b=”false”;
int i;
void f(int a){
i=a;
}
public void main(){
Test1 t=new Test1();
a=5;
t.f(a);
}
public class Father{
protected int i;
String j;
private int k;
public int m;
}
import folder1.Father;
public class Son extends Father{
public static void main(String[] args){
Son s=new Son();
s.i=1; s.j=”abc”; s.k=2; s.m=3;
}
}//其中Father放在folder1包内,Son放在folder2包内;
程序改错
大哥,明早考试啊。考查课的java!~~~
class Person {
static int count = 0;
protected String name;
protected int age; public Person(String n1, int a1) {
name = n1;
age = a1;
this.count++;
} public void print() {
System.out.println("name " + name + " age " + age + " count " + count);
}
}public class Student extends Person {
static int count = 0;
protected String dept; protected Student(String n1, int a1, String d1) {
super(n1, a1); // 调父类的构造方法
dept = d1;
this.count++;
} public static void main(String args[])
{ Person p1 = new Person("王小明",21) ;
p1.print(); // 之前没有定义这个方法
Student s1 = new Student("陈小瑞",19,"计算机系");
s1.print();
}
}
public class Test1 {
float f = 3.14f;
char c = '中';
boolean b = false;
int i; void f(int a) {
i = a;
} public static void main(String[] args) {
Test1 t = new Test1();
int a = 5;
t.f(a);
}
}
public class Father {
protected int i;
protected String j;
protected int k;
public int m;
}
import folder1.Father;public class Son extends Father {
public static void main(String[] args) {
Son s = new Son();
s.i = 1;
s.j = "abc";
s.k = 2;
s.m = 3;
}
}
public class Person {
static int count=0;
protected String name;
protected int age;
public Person(String n1,int a1){
name = n1; age = a1;
count++; // 这是静态变量,一个类只有一个, 不用加this
}
}
public class Student extends Person{
static int count=0;
protected String dept;
protected Student(String n1,int a1,String d1){
super(n1,a1);//父类构造函数里面需要参数,子类一定要给父类提供参数
dept = d1;
count++; //不用加this....
}
public static void main(String args[]){
Person p1 = new Person("王小明",21) ;
System.out.println(p1);
// p1.print(); //输出方法不正确
Student s1 = new Student("陈小瑞",19,"计算机系");
// Student s1 = new Student(‘陈小瑞’,19,‘计算机系’); //双引号不正确
System.out.println(s1);
// s1.print();
}
}
public class Test1 {
float f=3.14f; //3.14后面要加f
// char c= ’中’; //又是符号错误...
char c = '中';
// boolean b=”false”; //boolean型不用加引号
boolean b = false;
int i;
void f(int a){
i=a;
}
public void main(){
Test1 t=new Test1();
//a=5; //要添加数据类型
int a = 5;
t.f(a);
}
}
public class Son extends Father{
public static void main(String[] args){
Son s=new Son();
s.i=1;
// s.j=”abc”; 引号错误
s.j = "abc";
//s.k=2; int k 是父类的私有属性,不能继承到子类,子类没有此变量
s.m=3;
}
}都是基础,以后好好看看书就行了