The Artima Developer Community
Sponsored Link

Java Answers Forum
Method Overriding

1 reply on 1 page. Most recent reply: Oct 23, 2006 5:36 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Jenni jenni

Posts: 2
Nickname: jenni
Registered: Oct, 2006

Method Overriding Posted: Oct 21, 2006 10:22 AM
Reply to this message Reply
Advertisement
public class senior
{
private void aMethod()
{
System.out.println("I am in Parent class");
}
}
public class b extends a
{
public junior aMethod()
{
System.out.println("I am in Child Class");
}
}


public static void main(String args[]) {
junior boy1 = new junior();
int i = 5

if i == 5 then
call ... "the method from the sub class"

else

call ... " the method from Base class


}


How to achieve the above taks? Help me pleas.e

Thanks.
Jenni


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Method Overriding Posted: Oct 23, 2006 5:36 AM
Reply to this message Reply
1. When posting java code, use the java tags as shown in the "formatting your post" section

2. Let class names always begin with a capital letter, while packages and variable names begin with small letters. That makes the code easier to read.

3. what is a? what is b? I guess b should be junior and a should be senior.

4. You can cast your instance of junior to senior like this:
(senior)boy1 and this way access it's methods.

Flat View: This topic has 1 reply on 1 page
Topic: Java Problem Previous Topic   Next Topic Topic: How to execute an external file in java,where the file name is in Unicode ?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use