Write a Java class Author with following features: Instance variables: o firstName for the author’s first name of type String. o lastName for the author’s last name of type String.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Write a Java class Author with following features:
Instance variables:
o firstName for the author’s first name of type String.
o lastName for the author’s last name of type String.
Constructor:
o public Author (String firstName, String lastName): A constructor with
parameters, it creates the Author object by setting the two fields to the passed
values.
Instance methods:
o public void setFirstName (String firstName): Used to set the first name of author.
o public void setLastName (String lastName): Used to set the last name of author.
o public double getFirstName(): This method returns the first name of the author.
o public double getLastName(): This method returns the last name of the author.
o public void print(): This method printed out author’s complete name to the
screen
Trending now
This is a popular solution!
Step by step
Solved in 2 steps