Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Method overriding is a cornerstone of object-oriented programming in Java. It allows subclasses to inherit methods from their parent classes and provide specialized implementations. This powerful mechanism promotes code reusability and flexibility while fostering a clear hierarchy within your application’s architecture.
This quiz will test your understanding of key concepts related to method overriding in Java. By answering the questions, you’ll solidify your grasp of when and how to effectively override methods in your Java projects.
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 exhibited by Method overriding ?
Correct
Incorrect
Question 5 of 15
5. Question
class Override {
void display() {
System.out.println(“DataFlair”);
}
};
class Method extends Override {
void display(String a) {
System.out.println(a);
}
};
class Main {
public static void main ( String args [ ] )
{
Override o = new Override();
o.display();
Override o = new Method();
o.display(“DataFlair”);
}
}
Correct
Incorrect
Question 6 of 15
6. Question
class MethodOverride {
static void m1 ( ) {
System.out.println(“ This is a superclass static method “);
}
}
class Override extends MethodOverride{
static void m1 ( ) {
System.out.println(“ This is a subclass static method “);
}
};
class Main {
public static void main ( String args [ ] )
{
MethodOverride r = new Override();
r.m1();
}
}
Correct
Incorrect
Question 7 of 15
7. Question
Which of the following is not present in method overriding ?
Correct
Incorrect
Question 8 of 15
8. Question
class Demo {
final void calculate ( int a , int b )
{
int area = a*b;
System.out.println(area);
}
};
class Perimeter extends Demo {
void calculate ( int a , int b )
{
int perimeter = a+a+b+b;
System.out.println(perimeter);
}
}
class Main {
public static void main ( String args [ ] )
{
Demo d = new Demo();
d.calculate(1,2);
Demo d = new Perimeter();
d.calculate(1,2);
}
}
Correct
Incorrect
Question 9 of 15
9. Question
class Area {
public Area ( int a ) {
a +=5;
}
};
class Sample extends Area {
public Sample ( int a) {
a = a+5;
}
void calculate {
System.out.println(a*a);
}
}
class Main {
public static void main ( String args [ ] )
{
Area a = new Area();
a.Sample(5);
Sample s = new Sample();
s.calculate(a);
}
}
Correct
Incorrect
Question 10 of 15
10. Question
Which of the following cannot be overridden by Method Overriding ?
Correct
Incorrect
Question 11 of 15
11. Question
class Example {
void method ( String a) {
System.out.println(a);
}
void method( String b) {
System.out.println(b);
}
public static void main ( String args [ ] )
{
Example e = new Example ();
e.method(“DataFlair”);
}
}
Correct
Incorrect
Question 12 of 15
12. Question
interface One {
void print();
}
class Two implements One {
void print() {
System.out.println(“Interface is implemented”);
}
}
class Three extends Two {
void print() {
System.out.println(“Interface is implemented and class is also extended”);
}
}
class Main {
public static void main ( String args [ ] )
{
One o = new Three();
o.print();
}
}
Correct
Incorrect
Question 13 of 15
13. Question
Which of the given words are not used in method overridden concepts ?
Correct
Incorrect
Question 14 of 15
14. Question
class MethodOverridingDemo {
string a = “Superclass”;
void display () {
System.out.println(a);
}
}
class Demo extends MethodOverridingDemo {
String a = “Subclass”;
void display() {
System.out.println(a);
}
}
class Main {
public static void main ( String args [ ] )
{
MethodOverridingDemo d = new Demo();
d.display();
}
}
Correct
Incorrect
Question 15 of 15
15. Question
final class First {
int a = 10;
void display() {
System.out.println(a);
}
}
class Second extends First {
int b = 15;
void display() {
System.out.println(b + a);
}
}
class Third extends Second {
int c = 20;
void display() {
System.out.println(c+b+a);
}
}
class Main {
public static void main ( String args [ ] )
{
First f = new Third();
f.display();
}
}
Correct
Incorrect
Summary:
So you’ve taken the quiz and challenged your knowledge of Java method overriding! Did you identify the correct answers with ease, or were there a few concepts that required revisiting? Regardless of your score, this quiz served as a valuable learning tool.
Remember, effective mastery of method overriding requires consistent practice. Explore additional resources beyond this quiz, such as tutorials, code examples, and discussions with fellow Java programmers. By actively engaging with various learning materials, you’ll solidify your understanding and become proficient in crafting well-structured and reusable Java code.
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.
there are many printing mistakes in every question