2013年11月21日星期四

What is the method to achieve the air ?

The following procedure is wrong , one is prompted to "Test.java: 63: error: parse have reached the end of file
} ", but I checked , there is no lack of" } "Ah , another run to remind all the methods of abstract classes not covered , but I think not cover , I checked Baidu , said you can empty achieve , ask me how empty this program implements the abstract method in a class ?

import java.util.*;

public class Test
{
public static void main(String[] args)
{
Employee[] employee = new Employee[2];
employee[0] = new A("ert", "computer");
employee[1] = new B("rty", 5000);

for(Employee i: employee)
{
System.out.println(i.getName()+","+i.getMajor()+","+i.getSalary());
}

}
}

abstract class Employee
{
private String name;

public Employee(String n)
{
name = n;
}

  public String getName()
  {
   return name;
  }

 public abstract  String getMajor();
 public abstract double getSalary();
}

class A extends Employee
{
private String major; 
public A(String n, String m)
{
super(n);
major = m;
}
public String getMajor()
{
return major;    
}

class B extends Employee
{
private double salary;
public B(String n, double x)
{
super(n);
salary = x;
}

public double getSalary()
{
return salary;
}
}

------ Solution ------------------------------------- -------

class A extends Employee
{
        private String major; 
        public A(String n, String m)
        {
            super(n);
            major = m;
        }
        public String getMajor()
        {
            return major;          
        }//这里少个括号
}

------ Solution --------------------------- -----------------
class A getMajor way less of a "}" ;
classes A and B have one less implemented method
------ Solution ------------------------- -------------------
is no specific method body .
------ Solution ---------------------------------------- ----
empty implementation is nothing to write within the {}
------ Solution ----------------------- ---------------------


landlord to see red font , you are the method's return value is double , the method must return a value,
can write public void getSalary {

} Try

Do not forget to settle landlord posted

------ For reference only ---------------------------------------
Thank you, indeed one less } , in addition, A and B of the method less , how to make it? , The procedure variables in each class is fixed.
------ For reference only -------------------------------------- -
If nothing written inside { } will appear this error message " missing return statement ." In the A category is what I added
public double getSalary()
{

}



------ For reference only ---------------------------------- -----
public void getSalary () {

}

Sorry , fewer parentheses
------ For reference only ---------------------------------------
8 floor would not work . There will be " not covered by the abstract class method " error .
------ For reference only -------------------------------------- -
I generally Results posted soon , is waiting for the answer, this post I will end up with it. After more study, the more other , perhaps solved.
------ For reference only -------------------------------------- -
http://blog.csdn.net/shadowsick/article/details/8903278
I suggest you come to my blog to download a project examples , I believe you learn more help , which has a general usage
------ For reference only ---------------------------------------
you those methods have return values Therefore, the implementation is empty
public double getSalary () {
return null;
}
------ For reference only --------------------------------- ------
shadowsick, go to your blog to read, I was just entering JAVA, looking very basic knowledge , understand your project a little more difficult , my collection , and hope that their knowledge can be achieved after easy to understand the extent of your project . Thank you.
------ For reference only -------------------------------------- -
landlord, you do not quote you, we can not see your reply

没有评论:

发表评论