How to Code for Method Overriding in JAVA

      




Hello Coders !!!

Today, I'm going to start our Seventh Project from the "Series of Small JAVA Projects" to enlighten JAVA basics and make you understand by writing codes and executing them.

So, Let's start with today's topic 'How to Code for Method Overriding in JAVA' 

For Executing the code I'm going to use an IDE (Integrated Development Environment) called IntelliJ IDEA to run your code. This is one of the best IDE and very Smart IDE to help you write faster code in JAVA. Just Install its community version from its official website and start using it.

Steps to Create New Project in IntelliJ Idea as follows:-

---> Go to File > New > Project > Select Java  > click Next >...

check on Create project from template > & give your Project Name (I'm giving Seventh Project) > click on Finish.

---> Now click on a project folder and see the folder name 'src', hit right click on that folder and go to New then click on Package and give the name (I'm giving 'MethodOverriding' for this project) and hit Enter.

Now a new package will be created, then go to 'Print' & right-click, go to New & click on JAVA Class, go ahead and give a name for the JAVA class (I'm giving the name for this project 'Overriding') and hit Finish. 

Here we go, Our Project, Package & JAVA class is created.

Here's the Code!


package MethodOverriding;

class First
{
int x, y;
First(int a, int b)
{
x = a;
y = b;
}
void display()
{
System.out.println("x: " + x);
System.out.println("y: " + y);
}
}

class Second extends First
{
int z;
Second(int a, int b, int c)
{
super(a, b);
z = c;
}
void display()
{
super.display();
System.out.println("z: " + z);
}
}


public class Overriding {

public static void main(String args[])
{
Second sc = new Second(100, 200, 300);
sc.display();
}
}

/* If you aren't able to see full code on your mobile device, just rotate your screen to landscape mode. */

Tips:- After writing the code for the first time you need to "RUN" the code by hitting right-click and click on 'Run', only for the first time, after this, you can just click on the Run button available on Right-Hand Top corner.

This is 'How to Code for Method Overriding in JAVA& this is how we take One Value and Another Value and print out the desired results in JAVA. Go ahead and RUN the code and Comment your Results below.

Just Install IntelliJ IDEA from the link https://bit.ly/2RHmQRC and start coding.

For any queries you can just ask me in the comment below, I'll help you to the best of my knowledge.

Hope you like it. Stay Tuned, A lot more series of small JAVA projects are coming.

Don't forget to see our next project posting every other day.

Give your Love & Support. 

HAPPY CODING !!!


Comments

Popular posts from this blog

HOW TO WRITE "HELLO WORLD !" IN JAVA with CODE MODE

list of 10 UX problem-solving interview questions