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

The correct answers of these java questions: Question 1 In the following code, w

ID: 3890271 • Letter: T

Question

The correct answers of these java questions:

Question 1

In the following code, which is the error? (Assume that the elipses ... represent valid Java statements.)

try{

...
}

catch (Exception ex){
...
}
catch(RunTimeException ex){
...
}

  

Nothing is wrong.

  

The exceptions are in the wrong order.

  

You can't have two exceptions with one try.

The variable named ex cannot be re-used with the same try.

Question 2

In the following code, which is the error?

class Circle{
    double radius=1;
    Circle(){
    }
    Circle(double newRadius){
        radius=newRadius;
    }
}

  

Nothing is wrong.

  

There are two constructor methods.

The two constructors have different numbers of arguments.

  

newRadius ought not be declared as double.

Question 3

In the following code, which is the error? (Assume that the elipses ... represent valid Java statements.)

public class Course{
    private String courseName;
    private String[] students=new String[100];
    private int numberOfStudents;
    public Course(string courseName){
    ...
    }
    public String[] getStudents(){
    ...
    }
}

  

Nothing is wrong.

  

You can't return a String array from a method.

  

100 elements is more than is allowed in a String array.

The parameter type for the constructor is misspelled with a lowercase 's' in "string".

Question 4

In the following code which is the error? (Assume that the elipses ... represent valid Java statements.)

public class Parent {

                protected String name="Object";

                private String type="";

              public Parent(){

                …

               }

}

public class Child extends Parent {

               public Child(){

               …

               }

               public Child(double newName){

                    this.name=newName;

                    …

               }

}

  

Nothing is wrong.

A class which extends (inherits from) another class must NOT have its own constructor.

  

There is a mismatch of variable type.

The private variable inherited from the parent cannot be changed.

Explanation / Answer

1. The exceptions are in wrong order
2. Nothing is wrong
3.The parameter type for the constructor is misspelled with a lowercase 's' in "string".
4. There is a mismatch of variable type

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