Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is method overriding in OOP or Java? How many types are of polymorphism in java? Explain the difference between method overloading and method overriding.



  1. What is method overriding in OOP or Java?


  1. How many types are of polymorphism in java?



  1. Explain the difference between method overloading and method overriding.


  1. How to achieve abstraction in Java.



  1. Why Final keyword is used in Java. Explain with example.


Practical:


  1. Write a Java code to illustrate the concept of run-time polymorphism and generate the appropriate output.



  1. Write a Java code to illustrate the concepts of compile-time polymorphism.


3. Write a program to use abstract class and abstract method in Java.



Complete the missing programming steps:


1. Point out the error(s) and how they can be fixed in the following code:

public class B extends A {

private int a = 222;


public static void main(String[] args) {

System.out.println("in main(): ");

System.out.println("a = "+a);

a = 123;

}

}


public class A {

private int a = 100;

public void setA( int value) {

a = value;

}

public int getA() {

return a;

}

} //class A

2. Point out the error(s) and how they can be fixed in the following code:

public class OOPExercises {

public static void main(String[] args) {

A objA = new A( );

double result;

result = objA.getA( );

System.out.println("objA.a = "+ result);

}

}


public class A {

private int a = 100;

public void setA( int value) {

a = value;

}

public int getA() {

return a;

}

} //class A

3.Show the output of the code below:

public class OOPExercises {

static int a = 555;

public static void main(String[] args) {

A objA = new A();

B objB1 = new B();

A objB2 = new B();

C objC1 = new C();

B objC2 = new C();

A objC3 = new C();

objA.display();

objB1.display();

objB2.display();

objC1.display();

objC2.display();

objC3.display(); }

} Output:



public class A {

int a = 100;

public void display() {

System.out.printf("a in A = %d ", a);

}

} //class A

public class B extends A{

private int a = 123;

public void display() {

System.out.printf("a in B = %d ", a);

}

} //class B

public class C extends B {

private int a = 543;

public void display() {

System.out.printf("a in C = %d ", a);

}

} //class C

Step by Step Solution

3.30 Rating (147 Votes )

There are 3 Steps involved in it

Step: 1

1 Method Overriding in Java Method overriding is a feature of objectoriented programming that allows a subclass to provide a specific implementation of a method that is already provided by its supercl... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practicing Statistics Guided Investigations For The Second Course

Authors: Shonda Kuiper, Jeff Sklar

1st Edition

321586018, 978-0321586018

More Books

Students also viewed these Programming questions