This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

///abstract///

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abstract class can have static methods. True or False ?
True
Why true??How could we use the static method in abstract class?for example..
abstract class Test{
abstract void a();
static void b(){};
}
//compile OK
class A{ Test.b(); }
//compile error
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I create two classes to make sure I got this right, they are in two files, and it seems I got it right. Correct me if I am wrong.
Parent class, an abstract class with a static method.

child class that overrides one abstract method from the parent class and use the static method from the parent class.

output after running test2.class file.

I think what happened is that the abstract method has to be extended by the child class before inherintance occures. After that, when the child class is instanciated into an object, all the methods in the parent/abstract class is treated as if it is part of the child class and/or child object; test2 extends test, therefor the test2 class has the static method in test, and so that static method can be used as if it is written inside of the test2 class.
Am I rignt? Correct me if I am wrong.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a method is declares abstract the class must be declared abstract
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello chao-long
Your code doesn't compile because the method call is not placed within a method. Place it within one and it will compile. abstract means that the class cannot be instantiated. static means that you don't need an object of that class to call it, thus there is no contradiction.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic