Question 21
EasyWhat is a concrete class?
- A.
A class with only abstract methods
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
What is a concrete class?
A class with only abstract methods
A class with a complete implementation that can be instantiated
A class that cannot have objects
A class written in C only
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
class Sq(Shape):
def __init__(self, s):
self.s = s
def area(self):
return self.s * self.s
print(Sq(3).area())
None
Error
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
try:
Shape()
print("created")
except TypeError:
print("TypeError")
None
created
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
#include <iostream>
using namespace std;
class Shape {
public:
virtual int area() = 0;
virtual ~Shape() {}
};
class Rect : public Shape {
int w, h;
public:
Rect(int a, int b) : w(a), h(b) {}
int area() override { return w * h; }
};
int main() {
Shape* s = new Rect(2, 5);
cout << s->area();
delete s;
}
7
Compilation error
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
from abc import ABC, abstractmethod
class Animal(ABC):
@abstractmethod
def sound(self):
pass
def describe(self):
return "I say " + self.sound()
class Cow(Animal):
def sound(self):
return "moo"
print(Cow().describe())
moo
Error
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
#include <iostream>
using namespace std;
struct Shape {
virtual int sides() = 0;
virtual ~Shape() {}
};
struct Tri : Shape { int sides() override { return 3; } };
struct Quad : Shape { int sides() override { return 4; } };
int main() {
Shape* s[] = { new Tri(), new Quad(), new Tri() };
int t = 0;
for (Shape* x : s) {
t += x->sides();
delete x;
}
cout << t;
}
9
12
Sign up free to see the answer and a step-by-step explanation.
What is the main purpose of abstraction in large software systems?
Removing all classes
Reducing complexity by exposing only the essential features of each part
Making code longer
Making every field public
Sign up free to see the answer and a step-by-step explanation.
Which statements about abstract classes in Java are true? (Select all that apply.)
They can have constructors
They can be instantiated directly with new
They can have concrete (implemented) methods
They must contain at least one abstract method
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
try:
s = Shape()
print("Shape")
except TypeError:
print("Can't instantiate")
Can't instantiate
None
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
class Rect(Shape):
def __init__(self, w, h):
self.w, self.h = w, h
def area(self):
return self.w * self.h
print(Rect(3.0, 4).area())
0
12.0
Sign up free to see the answer and a step-by-step explanation.
9
6
TypeError
AttributeError
0
10
I say None
I say moo
10
11
0
Shape
None
Can't instantiate