In the topic Static keyword,”In the print statements, we tried to access the iWheel static variable with Toyota object but a compile time error thrown

package javaPracticeProgram;
        import vehicle.Car;
    public class TestStaticModifiers
public static void main(String[] args) {
        Car Toyota = new Car();
        Toyota.sModel=“Camry”;
        Toyota.iHighestSpeed = 230;
        Car.iDoors = 2;
        System.out.println(“Model of the Car: “ + Toyota.sModel);
        System.out.println(“Max speed of the Car: “ + Toyota.iHighestSpeed);
        System.out.println(“Number of Wheels in the Car: “ + Toyota.iWheel); //Compile Time Error
        System.out.println(“Number of Wheels in the Car: “ + Car.iWheel);
        System.out.println(“Number of Steering in the Car: “ + Car.iSteering);
        System.out.println(“Number of Doors in the Car: “ + Car.iDoors);
         }
    }
My code has executed successful i  doubt why compile time error should come??
since static variable can b accessed directly or using object,so i feel code is right and it shouldn’t throw compile time error
Default Asked on January 11, 2018 in Selenium WebDriver.
Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.