Question: Java C# abstract class A { private int x; public A ( ) { x = 7 ; } public A ( int y )

Java
C#
abstract class A {
private int x;
public A(){
x=7;
}
public A(int y){
x=y;
}
public abstract int do_stuff1();
public abstract int do_stuff2();
}
class B extends A {
public B(){
super(7);
}
public B(int y){
super(y);
}
@Override
public int do_stuff1(){
return 4;
}
@Override
public int do_stuff2(){
return 4;
}
}
class Main {
public static void main(String[] args){
B myB = new B(5);
}
}
using System;
abstract class A {
private int x;
public A(){
x=7;
}
public A(int y){
x=y;
}
public abstract int do_stuff1();
public abstract int do_stuff2();
}
class B : A {
public B() : base(7){
}
public B(int y) : base (y){
}
public override int do_stuff1(){
return 4;
}
public override int do_stuff2(){
return 4;
}
}
class MainClass {
public static void Main (string[] args){
B myB = new B(5);
}
}
Question 8 options:
No, class A cannot have a constructor since it's abstract.
No, class B can't have a constructor since it's inheriting from an abstract class A.
No, you can't use super/base to call a constructor in an abstract class.
Yes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!