67.8k views
3 votes
1. Provide Java code for a simple class of your choice. Be sure to include at least one constructor, two methods and two fields. The fields should be private.

2. Create a test class to constuct and call the methods of your class.
3. Describe your class and demonstrate your code functions properly.

User DrunkWolf
by
5.7k points

1 Answer

2 votes

Answer:

Step-by-step explanation:

public class Main

{

public static void main(String[] args) {

System.out.println("Test Class:");

Name name = new Name("Dayanand","Ghelaro");

System.out.println("First Name : "+name.getFirstName());

System.out.println("Last Name : "+name.getLastName());

}

}

class Name{

private String firstName; // first name field

private String lastName; // last name field

public Name(String firstName, String lastName){

this.firstName = firstName;

this.lastName = lastName;

}// end of constructor

public String getFirstName(){

return this.firstName;

} // end of method

public String getLastName(){

return this.lastName;

}// end of method

}// end of Name class

1. Provide Java code for a simple class of your choice. Be sure to include at least-example-1
User Dehli
by
5.0k points