Show List

Quiz - Java classes, objects, inheritance and polymorphism - 2

66%

Public Average Score
Select the right answer for below questions:

What is the use of a constructor in Java?
To create an instance of a class
To initialize the variables of an object
To define the behavior of an object
All of the above
To initialize the variables of an object

What is the use of an interface in Java?
To define a set of methods that a class must implement
To create an instance of a class
To provide a blueprint for creating objects
To allow multiple inheritance in a class
To define a set of methods that a class must implement

What is the use of the static keyword in Java?
To declare a static method
To declare a static variable
To declare a non-static method
None of the above
To declare a static variable

What is the purpose of the extends keyword in Java?
To declare a child-parent relationship between classes
To declare a relationship between two unrelated classes
To declare a parent-child relationship between classes
None of the above
To declare a parent-child relationship between classes

What is the purpose of the implements keyword in Java?
To declare a parent-child relationship between classes
To declare a child-parent relationship between classes
To declare a relationship between a class and an interface
None of the above
To declare a relationship between a class and an interface

What is the difference between inheritance and polymorphism in Java?
Inheritance allows a class to inherit properties and behaviors from another class, while polymorphism allows an object to take on many forms.
Inheritance allows an object to take on many forms, while polymorphism allows a class to inherit properties and behaviors from another class.
They are the same concept.
None of the above
Inheritance allows a class to inherit properties and behaviors from another class, while polymorphism allows an object to take on many forms.

What is the use of the protected keyword in Java?
To declare a private member
To declare a public member
To declare a member accessible only within the same class and its subclasses
None of the above
To declare a member accessible only within the same class and its subclasses

What is the difference between an abstract class and an interface in Java?
An abstract class can have method implementations, while an interface cannot. An interface can have multiple implementations, while an abstract class cannot.
An abstract class cannot have method implementations, while an interface can. An abstract class can have multiple implementations, while an interface cannot.
They are the same concept.
None of the above
An abstract class can have method implementations, while an interface cannot. An interface can have multiple implementations, while an abstract class cannot.

What is the use of the instanceof operator in Java?
To check if an object is an instance of an interface
To check if an object is an instance of a class or its subclass
To check if a class is a subclass of another class
None of the above
To check if an object is an instance of a class or its subclass

What is the purpose of the static method in Java?
To access a non-static member of a class
To access a static member of a class
To access an instance member of a class
None of the above
To access a static member of a class

Submit
Retry
{"qz1-335846":"To initialize the variables of an object","qz1-335847":"To define a set of methods that a class must implement","qz1-335848":"To declare a static variable","qz1-335849":"To declare a parent-child relationship between classes","qz1-335850":"To declare a relationship between a class and an interface","qz1-335851":"Inheritance allows a class to inherit properties and behaviors from another class, while polymorphism allows an object to take on many forms.","qz1-335852":"To declare a member accessible only within the same class and its subclasses","qz1-335853":"An abstract class can have method implementations, while an interface cannot. An interface can have multiple implementations, while an abstract class cannot.","qz1-335854":"To check if an object is an instance of a class or its subclass","qz1-335855":"To access a static member of a class"}

    Leave a Comment


  • captcha text