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

Java

 
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 
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 
To explain that, take a look at what is executed and why.

First of all, you create a new Derived-Instance as an instance of Base.

Take a look at how you call the static method foo():
You dont access it in a static way (to use exact the phrase the compiler will warn you with) - which would be Base.foo() or Derived.foo() - but you call it on an instance.

As mentioned, bObj is an instance of Base (because you declared it as that) and thus the static Method Base.foo() is called, which prints the "In Base.foo()"-Part of your output.

If you declared it as an instance of Derived, the static method Derived.foo() would have been called there.


To explain the part "In Derived.bar()" take a look at what is called next:
In Base.bar() you call bObj.bar();

bObj was instantiated with new Derived(), so the method bar() on that object is overriden with the implementation in Derived, which prints then "In Derived.bar()".


I hope that explains inheritance a bit better.

ab
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 
QuestionSEVERE: Error listenerStart Pin
r_mohd13-Sep-13 5:59
r_mohd13-Sep-13 5:59 
AnswerRe: SEVERE: Error listenerStart Pin
Richard MacCutchan13-Sep-13 6:36
mveRichard MacCutchan13-Sep-13 6:36 
QuestionHow we can call the hypercalls from the c program. Pin
cooldharma0613-Sep-13 1:22
cooldharma0613-Sep-13 1:22 
AnswerRe: How we can call the hypercalls from the c program. Pin
Richard MacCutchan13-Sep-13 2:58
mveRichard MacCutchan13-Sep-13 2:58 

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.