Exercise (Solutions)

E1

Study the below class:


class MyClass {

    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

Observe the indentation for System.out.println statement. Figure out why it has two tab indentation. Explain your answer.

E2

What is wrong with this class definition?

class MySecondClass (

)

E3

What is wrong with this class definition?

classMyThirdClass {

}

E4

What is wrong with this method definition?

mymethodname {

}

E5

What method must every application program have, to run as a standalone program?

E6

What must a statement end with?

E7

Write a program and give it a meaningful name as per the recommended convention and create three methods and invoke them like so:

The main method takes in one program argument and displays "Welcome " + name of the person invoking the program sent is as program argument.

Main method then invokes the method with the name displayFirstLessonTips In this method print out 1 or 2 sentences of what tips you would provide to a person trying to learn this lesson.

diplayFirstLessonTips will then invoke another method called sayGoodbye which will print out "Good bye" + name. I have not taught you how to send the program argument received in the main method to other methods yet. Can you do that?

results matching ""

    No results matching ""