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

Give short and yet thorough answers to the following questions. 1. If you attemp

ID: 3849283 • Letter: G

Question

Give short and yet thorough answers to the following questions. 1. If you attempt to add a float, an int, and a byte, what will be the type of the result? Explain. 2. Explain the difference between static and non-static variables. 3. When to use StringBuffer class instead of String ? 4. When to use the keyword final? 5. What is an Interface? 6. What is method Overloading? 7. What is the difference between Errors and Exceptions? 8. Checked exceptions are subject to a specific requirement. What is it?

Explanation / Answer

3. String is an immutable type. It cannot be changed, stringBuffer is not. When called for concatenations using += string uses string buffer in the background to do concatenation and then converts result to string.

4. Code speaks everything

        final int some;
        // Valid once
        some = 20;
        System.out.println("some = " + some);
      
        // Doesn't work the second time around. Oopsie!
        some = 30;
       

When you'd like to initialize the value later, once initialized you are not gonna change it.

6. Method overloading:

Having multiple methods in the same name but for different purposes.

    public static void main(String[] args) {      
        // Using method1
        double num1 = 20.3;
        double num2 = 22.0;      
        add(num1, num2);
    };
  
    // For adding floats. Method 1.
    public static void add(double a, double b) {
        System.out.println("Method 1 is called, result is: " + (a+b));
    };
  
    // For adding integers.
    public static void add(int a, int b) {
        System.out.println("Method 2 is called, result is: " + (a+b));
    }

1.

        Byte a = 10;
        int b = 10;
        float c = 12.0;
        Object var = a+b+c;
        System.out.println("a + b + c = " + var);

The answer is a double. The language will most likely use the highest precision possible to store the result(double / float here).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote