JAVA

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

JAVA

Post by answerhappygod »

JAVA
Java 1
Java 1 (81.88 KiB) Viewed 19 times
Submit your answers to the following questions: 1. Consider the following Java class (note the use of this in the setters): public class Book { private string title; private string author; public string getTitle() { return title; } public void setTitle(String title) { this.title= title; } public string getAuthor() { return author; } public void setAuthor (String author) { this.author = author; } What will the following code print when run? class Main { public static void main(String[] args) { Book b = new Book(); System.out.println(b.getTitle()); System.out.println(b.getAuthor()); 2. Using the same definition of Book as above, write the 3 lines of Java code you need to create a new Book titled "Where's Waldo?" by Martin Handford. 3. Now consider this different definition of the Book class (note the addition of a constructor): public class Book { private string title; private string author; public Book (String title, string author) { this.title = title; this.author = author; } public string getTitle() { return title; public string getAuthor() { return author; } What will the following code do? Why? class Main { public static void main(String[] args) { Book b = new Book(); System.out.println(b.getTitle()); System.out.println(b.getAuthor());
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply