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


<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.> 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 


<do not remove the three backticks above>

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.

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.

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