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).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started