Question
For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(A() called);
For Questions 1-3: consider the following code:
public class A
{
private int number;
protected String name;
public double price;
public A()
{
System.out.println(A() called);
}
private void foo1()
{
System.out.println(A version of foo1() called);
}
protected int foo2()
{
Sysem.out.println(A version of foo2() called);
return number;
}
public String foo3()
{
System.out.println(A version of foo3() called);
Return Hi;
}
}//end class A
public class B extends A
{
private char service;
public B()
{
super();
System.out.println(B() called);
}
public void foo1()
{
System.out.println(B version of foo1() called);
}
protected int foo2()
{
int n = super.foo2();
System.out.println(B version of foo2() called);
return (n+5);
}
public String foo3()
{
String temp = super.foo3();
System.out.println(B version of foo3());
return (temp+ foo3);
}
}//end class B
public class C extends B
{
public C()
{
super();
System.out.println();
}
public void foo1()
{
System.out.println(C version of foo1() called);
}
}//end class C
Assignment
- (20 pts) What is the output of this code sequence?
B b1 = new B();
- (20 pts) What is the output of this code sequence?
B b3 = new B();
int n = b3.foo2();
- (20 pts) What is the output of the following code?
//b4 is a B object reference
System.out.println(b4.foo3());
- (40 pts) You coded the following class:
public class N extends String, Integer
{
}
When you compile, you get the following message:
N.java:1: { expected
public class N extends String, Integer
^
1 error
Explain what the problem is and how to fix it.
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