import java.io.*;
import java.lang.*;
import java.util.*;
class First
{
public int No;
public String Name;
void getDetails() throws IOException
{
Scanner sc = new Scanner(System.in);
No = sc.nextInt();
Name = sc.nextLine();
}
void showDetails() throws IOException
{
System.out.println("The No and Name entered is: " +No +"\t" +Name);
}
}
class Second extends First
{
public double Salary;
public void showSalary() throws IOException
{
BufferedReader br = new BufferedReader ( new InputStreamReader (System.in) );
Salary = Double.parseDouble(br.readLine() );
System.out.println(" The salary for no:" +No +"is" +Salary);
}
}
class Demo_Inheritance
{
public static void main(String s[]) throws IOException
{
Second sd = new Second();
sd.getDetails();
sd.showDetails();
sd.showSalary();
First fs = new First();
fs.getDetails();
fs.showDetails();
fs.showSalary(); }
}
当我执行此编码时,我将最后一行中的错误称为“fs.showSalary()” - >找不到符号“。(点)”
答案 0 :(得分:2)
showSalary
中未定义方法First
。您需要添加方法或使用Second
的实例来使用方法
答案 1 :(得分:2)
编译器总是根据声明的访问类型来解析方法调用或字段访问。
由于fs
的声明类型为First
,编译器将在showSalary()
类中查找First
的方法声明,但找不到。{1}}。因此它给编译器错误。