Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. A class can have more than one constructor (true or false (4 pts.) 2. A const

ID: 3668732 • Letter: 1

Question

1. A class can have more than one constructor (true or false (4 pts.) 2. A constructor has the same name as the class (true or false) (4 pts.) 3. Circle the keyword below that is used to instantiate an object: (4 pts.) a. get b. set C. new d. static 4. In a class' API, we see this method: (3 pts. each) void foo a. what is the method name? b. how many arguments does the method take? c. does the method return a value? 5. In the same class, we also see this method API: (3 pts. each) double foo Bar int a a. How many arguments does this method take? b. What is the data type of the argument? c. What is the data type of the return value?

Explanation / Answer

1) true.

A class can have multiple constructors, as long as their signature (the parameters they take) are not the same. You can define as many constructors as you need. When a Java class contains multiple constructors, we say that the constructor is overloaded.

2) true

is a special type of method that is used to initialize the object.A constructor should always have same name as the class name.

3) The new operator instantiates a new object by allocating memory for it.

4) a) method name is foo

    b) it does not take any parameters because there are no arguments in ( ).

    c) method does not return any value because it is declared void. void does not have return value.

5) a) method takes only one argument that is 'a'.

     b) datatype of the argument is integer.

     c) datatype of return value is double.

6) Student stu=new Student(john,25);

           student is the constructor and stu is the object. name ans credits are passed as arguments.

10) Student stu1=new Student();

12) the output would be ABCDEFGHIJ.

      + operator in String concats two strings that is it combines two strings.

13) the output would be cms 167

       toLowerCase method converts uppercase letters to lowercase.

14) the output is 6.

       method string.length() retirns the length of the string.so the length of Autumn is 6.

15) um.

      this method returns a string which is the substring of given string. here 3 and 5 are start string and end string.

      start string is inclusive and end string is exclusive.

16) output is A

      string.charAt(int index) method returns the character at the specified index. here insed is 0 so it returns A

17) String wholeLine=scan.nextLine();

18) String petname=scan.nextLine();

19) scaner is in java.util.Scanner package

20) String class belongs to java.llang.String package