•Write a Java
class Author with following features:
•Instance variables :
–firstName for the author’s first name of type String.
–lastName for the author’s last name of type String.
•Instance methods:
–public void setFirstName
(String firstName): Used to set the
first name of author.
–public void setLastName
(String lastName): Used to set the
last name of author.
–public String getFirstName(): This method returns
the first name of the author.
–public String getLastName(): This method returns
the last name of the author.
class Author
{
String firstname,lastname;
void setfirstname(String first)
{
firstname=first;
}
void setlastname(String last)
{
lastname=last;
}
String getfirstname()
{
return firstname;
}
String getlastname()
{
return lastname;
}
public static void main(String[] args)
{
Author a1=new Author ();
a1.setfirstname("john");
a1.setlastname("k");
System.out.println("FirstName is"+a1.getfirstname()+"Last Nameis"+a1.getlastname());
}
}
No comments:
Post a Comment