Below are scan images of the questions for the assignment.

1 answer below »
Hello, I have an assignment that I need help on. The class is Object-Oriented and Concurrent Programming.
Below are scan images of the questions for the assignment.


Document Preview:

Below are scan images of the questions for the assignment.






Below are scan images of the questions for the assignment.
Answered Same DayDec 20, 2021

Answer To: Below are scan images of the questions for the assignment.

David answered on Dec 20 2021
127 Votes
10.1 What is the printout of running the class C in (a)?
Code:
public class A
{
public A()
{
System.out.println("A's no-arg constructor is invoked");
}
}

public class B extends A
{
}
public class C
{
public static void main(String[] args)
{
B b=new B();
}
}
Output:
What problem arises in compiling the problem in (b)?
Code:
public class A
{
public A(int x)
{
}
}
public class B extends A
{
public B()
{
}
}
public class C
{
public static void main(String[] args)
{
B b=new B();
}
}
Explanation:
1. No default constructor in Class A
2. Logical Error : In Class A, x value is not stored into class variable
Modified Code:
public class A
{
public int tx;
public A()
{
System.out.println("A's no-arg constructor is invoked");
}
public A(int x)
{
tx=x;
System.out.println("X value is "+tx);
}
}
public class B extends A
{
public B()
{
}
public B(int x)
{
super(x);
}
}
public class C
{
public static void main(String[] args)
{
B b=new B();
B b1=new B(5);
}
}
10.2 True or False?
1. A subclass is a subset of a superclass
Answer: False
2. When invoking a constructor from a subclass, its superclass’s no-arg constructor is
always invoked
Answer: True
3. You can override a private method defined in a superclass
Answer: False
4. You can override a static method defined in a superclass
Answer: False
10.3 Identify the problems in the following classes:
Answer:
Line 5 : radius = radius;
it should be replaced into
this.radius=radius;
Class variable refer by this keyword
Line 21:
Circle(radius);
It should be replaced into
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here