Click here to Skip to main content
15,898,373 members
Home / Discussions / Java
   

Java

 
QuestionPhp Pin
Member 1028500119-Sep-13 5:25
Member 1028500119-Sep-13 5:25 
AnswerRe: Php Pin
Richard MacCutchan19-Sep-13 21:03
mveRichard MacCutchan19-Sep-13 21:03 
AnswerRe: Php Pin
Usama Moud27-Sep-13 8:26
Usama Moud27-Sep-13 8:26 
Questionproblem with inheritance Pin
Asaf Shay18-Sep-13 1:59
Asaf Shay18-Sep-13 1:59 
QuestionRe: problem with inheritance Pin
Richard MacCutchan18-Sep-13 2:51
mveRichard MacCutchan18-Sep-13 2:51 
AnswerRe: problem with inheritance Pin
Asaf Shay19-Sep-13 9:17
Asaf Shay19-Sep-13 9:17 
GeneralRe: problem with inheritance Pin
jschell19-Sep-13 11:26
jschell19-Sep-13 11:26 
AnswerRe: problem with inheritance Pin
linaast18-Sep-13 20:38
linaast18-Sep-13 20:38 
You do not need to create the instance into base class. If you have base class, leave it, every class, which extends the base class as father class makes instances to it automatically. All you need is to put "super" modifier, if u need to call any function from your base class.

I suggest you to do like this in this case:

Java
public class OverrideTest{
 public static void main(String[] args){
  Derived dObj = new Derived();
  dObj.foo();
 } 
}

public class Derived extends Base{
 public void foo(){
  System.out.println("In Derived.foo()");
  super.foo();
 }
}

public class Base{
 public void foo(){
  System.out.println("In Base.foo()");
 }
}


Now your output will be:
"In Derived.foo()"
"In Base.foo()"

You do not need to use this:
Java
Base bObj = new Derived();

If You want to call the foo() method of Base class directly from yor Main class, remove the foo() method from your Derived class. In this case, the foo() method will be called from Base class automatically.

modified 19-Sep-13 9:53am.

GeneralRe: problem with inheritance Pin
Asaf Shay19-Sep-13 9:24
Asaf Shay19-Sep-13 9:24 
AnswerRe: problem with inheritance Pin
Mr_z22-Sep-13 10:36
Mr_z22-Sep-13 10:36 
AnswerRe: problem with inheritance Pin
Usama Moud27-Sep-13 9:36
Usama Moud27-Sep-13 9:36 
AnswerRe: problem with inheritance Pin
angrybobcat29-Sep-13 9:57
angrybobcat29-Sep-13 9:57 
AnswerRe: problem with inheritance Pin
Vivek Vermani13-Jan-14 12:04
Vivek Vermani13-Jan-14 12:04 
QuestionPlease Help with a Java code Pin
Adewagold16-Sep-13 22:01
Adewagold16-Sep-13 22:01 
AnswerRe: Please Help with a Java code Pin
Richard MacCutchan17-Sep-13 0:33
mveRichard MacCutchan17-Sep-13 0:33 
AnswerRe: Please Help with a Java code Pin
Member 1028017517-Sep-13 7:04
Member 1028017517-Sep-13 7:04 
QuestionJSpinner Value into Database? Pin
chdboy15-Sep-13 19:46
chdboy15-Sep-13 19:46 
AnswerRe: JSpinner Value into Database? Pin
Richard MacCutchan15-Sep-13 21:20
mveRichard MacCutchan15-Sep-13 21:20 
GeneralRe: JSpinner Value into Database? Pin
chdboy15-Sep-13 21:31
chdboy15-Sep-13 21:31 
GeneralRe: JSpinner Value into Database? Pin
Richard MacCutchan15-Sep-13 21:43
mveRichard MacCutchan15-Sep-13 21:43 
GeneralRe: JSpinner Value into Database? Pin
chdboy17-Sep-13 3:46
chdboy17-Sep-13 3:46 
GeneralRe: JSpinner Value into Database? Pin
Richard MacCutchan17-Sep-13 3:55
mveRichard MacCutchan17-Sep-13 3:55 
Questionjoin Pin
Member 1027264513-Sep-13 7:32
Member 1027264513-Sep-13 7:32 
AnswerRe: join Pin
jschell13-Sep-13 11:39
jschell13-Sep-13 11:39 
AnswerRe: join Pin
Richard MacCutchan13-Sep-13 22:46
mveRichard MacCutchan13-Sep-13 22:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.