May I please get some help for exercise 7 of Object oriented programming in java?


#1



https://www.codecademy.com/en/courses/learn-java/lessons/object-oriented-programming/exercises/objects?action=resume

Dog.java:15: error: class, interface, or enum expected
public static void main(String[] args) {Dog dogsAge = new
^
1 error


class Dog {
  
   
   public Dog(int dogsAge) {
 
     age = dogsAge;
  }
}
	public static void main(String[] args) {Dog dogsAge = new
  
       Dog dogsAge = new 
  
}

Can anyone help me please? If I am to become a software designer someday and go to school with some knowledge of coding, I must be able to learn java.


#2

You can find all problems with your code by analyzing the example:

class Car {
    int modelYear;
    public Car(int year) {
        modelYear = year;
    }

    public static void main(String[] args){
        Car myFastCar = new Car(2007);
    }
}

As you see, method main is inside the Car class. And in this line:

Car myFastCar = new Car(2007);

we have used Car constructor to create a Car object with parameter year set to 2007 and we assigned this object to variable myFastCar.

You just really need to modify this example to your needs.


If you want to become a programmer you have to learn how to read and learn from codes written by others.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.