Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

33%
+0 −2
Q&A What are the disadvantages of using static methods in Java?

If it were always better to use static, the language would have been designed to always assume static, or at least default to static. That the language defaults to making methods not static indicat...

posted 3y ago by meriton‭  ·  edited 3y ago by meriton‭

Answer
#4: Post edited by user avatar meriton‭ · 2021-09-19T20:36:19Z (over 3 years ago)
  • If it were always better to use `static`, the language would have been designed to always assume `static`, or at least default to `static`. That the language defaults to making methods not static indicates that the designers of the programming language envisioned static methods to be rare.
  • Java is intended to be an object oriented programming language, where a program is a set of objects that "talk" to each other using methods. Objects are created from classes, and classes can be related through inheritance. Specifically, a class can be declared to extend another class, which allows it to inherit or override methods from the parent class. For instance:
  • class Animal {
  • void move() {
  • System.out.prinln("The animal moves");
  • }
  • }
  • class Dog {
  • @Override
  • void move() {
  • System.out.println("The dog walks");
  • }
  • }
  • class Snake {
  • @Override
  • void move() {
  • System.out.println("The snake slithers");
  • }
  • }
  • Which you can then use as follows:
  • Animal animal = new Snake();
  • animal.move(); // "The snake slithers"
  • So even though the variable contains an `Animal`, that `Animal` knows whether it is a `Dog` or a `Snake`, and responds accordingly when it is asked to `move`.
  • This ability to refine the behavior of a class in a subclass is very useful. However, since this depends on the type of the object, it is only available for methods of objects, not static methods.
  • By using static, you deny yourself this useful tool. This may seem a small price to pay when your programs are tiny and consist only of a few isolated methods. However, once your programs get bigger, and particularly once they start incorporating code written by other people, the ability to refine code they have written will be invaluable.
  • If it were always better to use `static`, the language would have been designed to always assume `static`, or at least default to `static`. That the language defaults to making methods not static indicates that the designers of the programming language envisioned static methods to be rare.
  • Java is intended to be an object oriented programming language, where a program is a set of objects that "talk" to each other using methods. Objects are created from classes, and classes can be related through inheritance. Specifically, a class can be declared to extend another class, which allows it to inherit or override methods from the parent class. For instance:
  • class Animal {
  • void move() {
  • System.out.prinln("The animal moves");
  • }
  • }
  • class Dog extends Animal {
  • @Override
  • void move() {
  • System.out.println("The dog walks");
  • }
  • }
  • class Snake extends Animal {
  • @Override
  • void move() {
  • System.out.println("The snake slithers");
  • }
  • }
  • Which you can then use as follows:
  • Animal animal = new Snake();
  • animal.move(); // "The snake slithers"
  • So even though the variable contains an `Animal`, that `Animal` knows whether it is a `Dog` or a `Snake`, and responds accordingly when it is asked to `move`.
  • This ability to refine the behavior of a class in a subclass is very useful. However, since this depends on the type of the object, it is only available for methods of objects, not static methods.
  • By using static, you deny yourself this useful tool. This may seem a small price to pay when your programs are tiny and consist only of a few isolated methods. However, once your programs get bigger, and particularly once they start incorporating code written by other people, the ability to refine code they have written will be invaluable.
#3: Post edited by user avatar meriton‭ · 2021-09-19T20:35:43Z (over 3 years ago)
  • If it were always better to use `static`, the language would have been designed to always assume `static`, or at least default to `static`. That the language defaults to making methods not static indicates that the designers of the programming language envisioned static methods to be rare.
  • Java is intended to be an object oriented programming language, where a program is a set of objects that "talk" to each other using methods. Objects are created from classes, and classes can be related through inheritance. Specifically, a class can be declared to extend another class, which allows it to inherit or override methods from the parent class. For instance:
  • class Animal {
  • void move() {
  • System.out.prinln(this + " moves");
  • }
  • }
  • class Dog {
  • @Override
  • void move() {
  • System.out.println("The dog walks");
  • }
  • }
  • class Snake {
  • @Override
  • void move() {
  • System.out.println("The snake slithers");
  • }
  • }
  • Which you can then use as follows:
  • Animal animal = new Snake();
  • animal.move(); // "The snake slithers"
  • So even though the variable contains an `Animal`, that `Animal` knows whether it is a `Dog` or a `Snake`, and responds accordingly when it is asked to `move`.
  • This ability to refine the behavior of a class in a subclass is very useful. However, since this depends on the type of the object, it is only available for methods of objects, not static methods.
  • By using static, you deny yourself this useful tool. This may seem a small price to pay when your programs are tiny and consist only of a few isolated methods. However, once your programs get bigger, and particularly once they start incorporating code written by other people, the ability to refine code they have written will be invaluable.
  • If it were always better to use `static`, the language would have been designed to always assume `static`, or at least default to `static`. That the language defaults to making methods not static indicates that the designers of the programming language envisioned static methods to be rare.
  • Java is intended to be an object oriented programming language, where a program is a set of objects that "talk" to each other using methods. Objects are created from classes, and classes can be related through inheritance. Specifically, a class can be declared to extend another class, which allows it to inherit or override methods from the parent class. For instance:
  • class Animal {
  • void move() {
  • System.out.prinln("The animal moves");
  • }
  • }
  • class Dog {
  • @Override
  • void move() {
  • System.out.println("The dog walks");
  • }
  • }
  • class Snake {
  • @Override
  • void move() {
  • System.out.println("The snake slithers");
  • }
  • }
  • Which you can then use as follows:
  • Animal animal = new Snake();
  • animal.move(); // "The snake slithers"
  • So even though the variable contains an `Animal`, that `Animal` knows whether it is a `Dog` or a `Snake`, and responds accordingly when it is asked to `move`.
  • This ability to refine the behavior of a class in a subclass is very useful. However, since this depends on the type of the object, it is only available for methods of objects, not static methods.
  • By using static, you deny yourself this useful tool. This may seem a small price to pay when your programs are tiny and consist only of a few isolated methods. However, once your programs get bigger, and particularly once they start incorporating code written by other people, the ability to refine code they have written will be invaluable.
#2: Post edited by user avatar meriton‭ · 2021-09-19T20:34:36Z (over 3 years ago)
  • If it were always better to use `static`, the language would have been designed to always assume `static`, or at least default to `static`. That the language defaults to making methods not static indicates that the designers of the programming language envisioned static methods to be rare.
  • Java is indented to be an object oriented programming language, where a program is a set of objects that "talk" to each other using methods. Objects are created from classes, and classes can be related through inheritance. Specifically, a class can be declared to extend another class, which allows it to inherit or override methods from the parent class. For instance:
  • class Animal {
  • void move() {
  • System.out.prinln(this + " moves");
  • }
  • }
  • class Dog {
  • @Override
  • void move() {
  • System.out.println("The dog walks");
  • }
  • }
  • class Snake {
  • @Override
  • void move() {
  • System.out.println("The snake slithers");
  • }
  • }
  • Which you can then use as follows:
  • Animal animal = new Snake();
  • animal.move(); // "The snake slithers"
  • So even though the variable contains an `Animal`, that `Animal` knows whether it is a `Dog` or a `Snake`, and responds accordingly when it is asked to `move`.
  • This ability to refine the behavior of a class in a subclass is very useful. However, since this depends on the type of the object, it is only available for methods of objects, not static methods.
  • By using static, you deny yourself this useful tool. This may seem a small price to pay when your programs are tiny and consist only of a few isolated methods. However, once your programs get bigger, and particularly once they start incorporating code written by other people, the ability to refine code they have written will be invaluable.
  • If it were always better to use `static`, the language would have been designed to always assume `static`, or at least default to `static`. That the language defaults to making methods not static indicates that the designers of the programming language envisioned static methods to be rare.
  • Java is intended to be an object oriented programming language, where a program is a set of objects that "talk" to each other using methods. Objects are created from classes, and classes can be related through inheritance. Specifically, a class can be declared to extend another class, which allows it to inherit or override methods from the parent class. For instance:
  • class Animal {
  • void move() {
  • System.out.prinln(this + " moves");
  • }
  • }
  • class Dog {
  • @Override
  • void move() {
  • System.out.println("The dog walks");
  • }
  • }
  • class Snake {
  • @Override
  • void move() {
  • System.out.println("The snake slithers");
  • }
  • }
  • Which you can then use as follows:
  • Animal animal = new Snake();
  • animal.move(); // "The snake slithers"
  • So even though the variable contains an `Animal`, that `Animal` knows whether it is a `Dog` or a `Snake`, and responds accordingly when it is asked to `move`.
  • This ability to refine the behavior of a class in a subclass is very useful. However, since this depends on the type of the object, it is only available for methods of objects, not static methods.
  • By using static, you deny yourself this useful tool. This may seem a small price to pay when your programs are tiny and consist only of a few isolated methods. However, once your programs get bigger, and particularly once they start incorporating code written by other people, the ability to refine code they have written will be invaluable.
#1: Initial revision by user avatar meriton‭ · 2021-09-19T20:33:56Z (over 3 years ago)
If it were always better to use `static`, the language would have been designed to always assume `static`, or at least default to `static`. That the language defaults to making methods not static indicates that the designers of the programming language envisioned static methods to be rare.

Java is indented to be an object oriented programming language, where a program is a set of objects that "talk" to each other using methods. Objects are created from classes, and classes can be related through inheritance. Specifically, a class can be declared to extend another class, which allows it to inherit or override methods from the parent class. For instance:

    class Animal {
       void move() {
           System.out.prinln(this + " moves");
       }
    }

    class Dog {
       @Override
       void move() {
           System.out.println("The dog walks");
       }
    }

    class Snake {
       @Override
       void move() {
           System.out.println("The snake slithers");
       }
    }

Which you can then use as follows:

    Animal animal = new Snake();
    animal.move(); // "The snake slithers"

So even though the variable contains an `Animal`, that `Animal` knows whether it is a `Dog` or a `Snake`, and responds accordingly when it is asked to `move`. 

This ability to refine the behavior of a class in a subclass is very useful. However, since this depends on the type of the object, it is only available for methods of objects, not static methods.

By using static, you deny yourself this useful tool. This may seem a small price to pay when your programs are tiny and consist only of a few isolated methods. However, once your programs get bigger, and particularly once they start incorporating code written by other people, the ability to refine code they have written will be invaluable.