简体   繁体   中英

System.out.println - println is not correctly spelled in Eclipse IDE

I just started using the Eclipse IDE and for a first test I created a file and entered the following:

class Vehicle {
   public Vehicle(String s) {
      System.out.println("X");
   }
   // public Vehicle() { }  
}
public class Car extends Vehicle {
   public Car(String s) {
      System.out.println("Y");
   }
   public static void main(String [] args) {
      new Car("Z");
   }
}

But I immediately get errors saying println is not correctly spelled. Can someone tell me if there's something I am missing?

I think you have created an txt file instead of a JAVA file.

Because of this it is not able to recognize keywords related to java, thereby giving error that the word is not correctly spelled. If you will change println to print ,it will stop giving error.As Print is a proper word in English. But here you need to change extension of file from .txt to .java

In Eclipse click on File Menu -> New -> Class Give Class name as Car and Click on Finish button. It will create Car.java file. Then in Car.java file write below code

class Vehicle { 
   public Vehicle(String s) { 
      System.out.println("X"); 
   } 
    public Vehicle() { }  
  }
 public class Car extends Vehicle {  
  public Car(String s) {    
   System.out.println("Y");   
 }   
 public static void main(String [] args) { 
      new Car("Z"); 
   } 
} 

In the Vehicle class defult constructor is required as Class Car extending Vehicle class.Otherwise it will show error as 'Implicit super constructor Vehicle() is undefined. Must explicitly invoke another constructor' for constuctor of Car class. Now just run the file s Java Application. It will show output as Y on console.

I just received this error and the fix was to restart Eclipse. This error seems very random.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM