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
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
// Formats 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?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
