Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Abstract classes are a cornerstone of object-oriented programming (OOP) in Java. They act as a template, defining a blueprint for creating families of related objects. This approach not only promotes code reusability but also enforces a common structure and behavior across these objects. Imagine a blueprint for a house – it defines the overall layout, foundation, and basic elements that all houses share.
Abstract classes work in a similar way, providing a foundation for related objects while allowing flexibility for specific implementations. Just like different house plans might specify unique features like the number of bedrooms or presence of a garage, subclasses of an abstract class can provide their own concrete implementations for specific functionalities.
This quiz on abstract classes in Java delves into these key characteristics and functionalities, helping you solidify your understanding of this powerful concept. By tackling the challenges presented, you’ll gain valuable insights into how abstract classes promote code organization, reusability, and flexibility in object-oriented programming.
Time limit: 0
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Which of the following is true about abstract classes in Java ?
Correct
Incorrect
Question 2 of 15
2. Question
abstract class AbstractClass {
public void method();
}
class Subclass derived AbstractClass {
public void method(String a)
{
System.out.println(a);
}
}
class Main {
public static void main ( String args [ ] )
{
AbstractClass a = new Subclass();
a.method(“DataFlair”);
}
}
Correct
Incorrect
Question 3 of 15
3. Question
abstract class One {
One() {
System.out.println(“Constructor is called”);
}
abstract void function();
}
class Demo extends One {
abstract void abstract()
{
System.out.println(“Subclass constructor is called”);
}
}
class Main {
public static void main ( String args [ ] )
{
One o = new One();
}
}
Correct
Incorrect
Question 4 of 15
4. Question
Which of the following is not true about abstract classes in Java ?
Correct
Incorrect
Question 5 of 15
5. Question
class Demo {
abstract void method1();
}
class Sample extends Demo {
abstract void method1() {
System.out.println(“This is a Sample Class”);
}
}
class Main {
public static void main ( String args [ ] )
{
Demo d = new Sample();
d.method1();
}
}
Correct
Incorrect
Question 6 of 15
6. Question
abstract class Abstraction {
abstract void calculate(int a , int b)
{
System.out.println(a*b);
}
]
class Sample extends Abstraction {
public void calculate( int a , int b );
}
class Main {
public static void main ( String args [ ] )
{
Abstraction a = new Sample();
a.calculate(2,4);
}
}
Correct
Incorrect
Question 7 of 15
7. Question
Which keyword is used to inherit an abstract class ?
Correct
Incorrect
Question 8 of 15
8. Question
abstract class Abstraction {
public void Square(int a);
}
class Example extends Abstraction {
public Example() {
System.out.println(“Constructor”);
}
public void Square(int a )
{
System.out.println(a*a);
}
}
class Main {
public static void main ( String args [ ] )
{
Abstraction a = new Example();
a.Square(3);
}
}
Correct
Incorrect
Question 9 of 15
9. Question
abstract class First {
First() {
System.out.println(“ Abstract class constructor”);
}
public void math(int a , int b );
}
class Function extends First {
Function() {
System.out.println(“Extended class constructor”);
}
public void math( int a , int b )
{
System.out.println(a+b);
}
} class Main {
public static void main ( String args [ ] )
{
First f = new Function();
f.math(3,8);
}
}
Correct
Incorrect
Question 10 of 15
10. Question
Which of these is not used to declare a method in abstract class ?
Correct
Incorrect
Question 11 of 15
11. Question
abstract class SampleClass {
public void demo ( )
{
System.out.println(“Method is defined here”);
}
class Second extends SampleClass {
}
class Main {
public static void main ( String args [ ] )
{
SampleClass s = new Second();
s.demo();
}
}
Correct
Incorrect
Question 12 of 15
12. Question
abstract class AbstractionDemo {
abstract void display();
}
class Main extends Abstraction demo {
public static void main ( String args [ ] )
{
abstract void display()
{
System.out.println(“Main Function”);
}
AbstractionDemo d = new Main();
d.display();
}
}
Correct
Incorrect
Question 13 of 15
13. Question
What is the reason for constructor in abstract class ?
Correct
Incorrect
Question 14 of 15
14. Question
abstract class Super {
public void simple(String a);
}
class Sub extends Super {
public void simple(String a)
{
System.out.println(a);
}
}
class Main {
public static void main ( String args [ ] )
{
Super s = new Super();
s.simple(“DataFlair”);
}
}
Correct
Incorrect
Question 15 of 15
15. Question
abstract class Main {
static void function() {
System.out.println(“Static method”);
}
class MainFunction extends Main {
public static void main ( String args [ ] )
{
Main.function();
}
}
Correct
Incorrect
Summary:
So you’ve taken the quiz and put your knowledge of abstract classes in Java to the test! How did you fare? Regardless of your score, this quiz serves as a valuable learning tool. For any questions answered incorrectly, revisit the explanations provided to solidify your understanding.
Remember, effective mastery of abstract classes is crucial for building robust and maintainable object-oriented applications in Java. Explore additional resources beyond this quiz, such as tutorials and practice problems, to further enhance your grasp of this important concept.
Did we exceed your expectations? If Yes, share your valuable feedback on Google
DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.