0% found this document useful (0 votes)
11 views

Java Method and Contructor Questions

Uploaded by

aj.ajay02nd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Java Method and Contructor Questions

Uploaded by

aj.ajay02nd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

Create a class Book with three constructors: one default (set values to unknown / 0), one that
takes title and author, and another that takes title, author, and price. Print the values.
2. Implement a copy constructor in a class Employee that copies values from another object.
3. Create a class Account with overloaded constructors - default (sets account balance to 0) and
parameterized (to set the account balance from parameter) that validate the account balance. If
the balance is negative, throw an exception.
4. Create a class called Concatenator that overloads methods for concatenating different types of
data. Implement the following:
a. concatenate(String a, String b) - Concatenate two strings.
b. concatenate(String a, int b) - Concatenate a string and an integer.
c. concatenate(int a, int b) - Concatenate two integers (as strings).
d. concatenate(String a, String b, String c) - Concatenate three strings.
5. Create a class called Logger that provides overloaded methods for logging messages with
different levels of severity. Implement the following:
a. log(String message) - Log a general message.
b. log(String message, int severity) - Log a message with a severity level (1-5).
c. log(String message, Exception e) - Log a message with an associated exception stack
trace.
d. log(String message, String timestamp) - Log a message with a custom timestamp.
6. Create a class called Converter that provides overloaded methods for converting data types.
Implement the following:
a. convert(String str) - Convert a string to an integer (or return a default value if it fails).
b. convert(int number) - Convert an integer to a string.
c. convert(double value) - Convert a double to a string with 2 decimal places.

You might also like