Vous êtes sur la page 1sur 3

Object Oriented

Programming
Assignment-2

Prepared By:
Student ID
Student Name:

Task 1
Solution
It will return 6

Task 2
Solution

public class Person {


private String firstName="";
private String lastName="";
Public Person( String first, String last ) { // no need of void here
firstName = first;
lastName = last;
} // end Person constructor
Public string getFirstName() {// return data type was missing
return firstName;
} // end method getFirstName
Public string getLastName() {
return lastName ;
} // end method getLastName
} // end class Person
public class JavaApplication3 {
public static void main(String[] args) {
Person test = new Person( "John", "Smith"); //object name must be different
System.out.printf( "Happy Birthday to %s %s \n", test.getFirstName(),
test.getLastName() ); // add %s for second string value
// call the function with object and dot operator
}
}

Task 3
Solution

Vous aimerez peut-être aussi