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

Question 1: Assuming that the following classes have been defined: public class

ID: 3860212 • Letter: Q

Question

Question 1:

Assuming that the following classes have been defined:

      public class A

      {

public static void method1()

    {

                  System.out.println("A1");

          }

      }

      public class B extends A

      {

          public static void method2()

    {

    System.out.println("B2");

    }

      }

      public class C extends B

      {

          public static void method1()

    {

                  System.out.println("C1");

          }

      }

And assuming the following objects have been defined:

      A a = new A();

    B b = new B();

    B other2 = new C();

In the table below, indicate in the right-hand column the output produced by the statement in the left-hand column. If the statement causes an error, fill in the right-hand column with either the phrase "compiler error" or "runtime error" to indicate when the error would be detected.

      Statement               Output

      ---------------------------------------------------------------------

      a.method1();                  __________________

      a.method2();                  __________________

      b.method1();                  __________________

      b.method2();                  __________________

      other2.method1();            __________________

      other2.method2();             __________________

Question 2:

Write Java code to create a new class called “Student”. An object of the Student class has private attributes - student id, name and address. Instantiate an array object of this class, with these attributes (for 2 objects). Thereafter, display these attributes to a user. (Your code should include entire class and a driver to demonstrate the above).

Question 3:

In this question, you must write part of a "main" method to solve a problem using two classes that you can assume are provided already.

Here are the classes that are provided. The contents of the methods are omitted, because you don't need to know how they work.

class Person {

public int howManyChildren() { ... }

// returns an integer that is the number of children the Person has

   public String getName() { ... }

       // returns the name of the Person

}

class PersonReader {

   public PersonReader() { ... }

// a constructor - creates its own Reader object, and whatever else it needs

   public Person readPerson() { ... }

   // reads enough input data to make an object of the class Person, and returns that object. (This is like

   // Format’s readLine( ) method, which reads and returns a String.

}

Complete the program below. It is intended to read the data about 20 people, storing each in an object of type Person. Then it prints the name of the Person(s) with the largest number of children. Your code should handle case where two or more parents have the same number of children (that could be highest).

public class WhoHasTheMostChildren {

   public static void main (String[] args) {

       .....

  

   }

}

Question 5;

1) Write an example to demonstrate overriding of static methods?

2) How is dynamic binding useful in enabling a small executable size in Java? Explain.

Question 5:

Apply your favorite sorting algorithm and show status of data after 7th round of sorting:

Data Set

      -5, -10, 25, 19, 94, 98, 256, 77, 87, 64, -94, 175, 92, -55,

Question 6:

a. For Student class written in Question 2 (You can attempt this question even if you have not done question 2), create a method that populates an array of Students using Scanner inside a method and returns an array object with populated information.

b. How is the end of file determined for java text files?

Explanation / Answer

Hey,

Since you have asked multiple question here, so as per chegg, I will answer only first question. For other questions, Please ask seperately.

Answer for first question:

Note that in the question, all classes have static methods. We shouldn't call a static method from a object because the static method belongs to a class. It would be logically incorrect to call static methods from object. Nevertheless, java compiler allow it, and won't give you error if you call them. However, If you happen to use any IDE like intellij IDEA, then the IDE will give warning about it. So keep that in mind ;-)

1) a.method1() -> It will print A1 since method1 is in class A and compiler allows to call static methods from objects.

2) a.method2() -> This will give compile time error. It is because method2 belong to class B and class A knows nothing about class B as it is the superclass of B. So compiler will complain that it cannot find symbol method2()

3) b.method1() -> It will print A1 because class B extends from A and thus inherits its methods.

4) b.method2() -> It will print B2 since method2 is in class B and compiler allows to call static methods from objects.

5) other2.method1() -> other2 is an C's object stored in B's variable. Therefore calling method1() will print A1.

6) other2.method2() -> as explained above, other2 is an C's object stored in B's variable. Therefore calling method2() will print B2.

Hope it helps!

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