Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New program using extends and the use of method overriding with acces… #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Methods
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// A Simple Java program to demonstrate
// Overriding and Access-Modifiers

class Parent {
// private methods are not overridden
private void m1()
{
System.out.println("From parent m1()");
}

protected void m2()
{
System.out.println("From parent m2()");
}
}

class Child extends Parent {
// new m1() method
// unique to Child class
private void m1()
{
System.out.println("From child m1()");
}

// overriding method
// with more accessibility
@Override
public void m2()
{
System.out.println("From child m2()");
}
}

// Driver class
class Main {
public static void main(String[] args)
{
Parent obj1 = new Parent();
obj1.m2();
Parent obj2 = new Child();
obj2.m2();
}
}