This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Statics

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class A{
static void get1(){
System.out.println("A s get1");
}
void get2(){
System.out.println("A s get2");
}
void get(){
get1();
get2();
}
}

public class Whiz35 extends A{
static void get1(){
System.out.println("Whiz s get1");
}
void get2(){
System.out.println("Whiz s get2");
}

public static void main(String... args){
new Whiz35().get();
}
}

How could non static classes would be called from non static i.e get()???
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well!!
May be i am not sure with this
what i can say on this is

Whiz35 extends class A
so it can inherit all methods
of class A
And in the main you are
creating an instance
using that you are calling
the method get()
inherited from class A

public static void main(String... args){
new Whiz35().get();
}


Generally
In main we create object of class
then using dot operator we call
methods (not compulsory they must be static)
Here above you are using instance of class
to call the method!!


i hope it helps!!!
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Output is:


why not "Whiz s get1
Whiz s get2"?
polymorphism at runtime is only for instance method?
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

polymorphism at runtime is only for instance method?


Yes.
See also this: Polymorphism


Bu.
 
I didn't say it. I'm just telling you what this tiny ad said.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic