Why cannot we use static keyword inside a method in java?

Let’s learn why cannot we use static keyword inside a method in java. The most accurate or helpful solution is served by Stack Overflow.

There are ten answers to this question.

Best solution

When NOT to use the static keyword in Java?

When is it considered poor practice to use the static keyword in Java on method signatures? If a method performs a function based upon some arguments, and does not require access to fields that are not static, then wouldn't you always want these types of methods to be static?

Answer:

One reason why you may not want it to be static is to allow it to be overridden in a subclass. In other...

Read more

Brian Reindel at Stack Overflow Mark as irrelevant Undo

Other solutions

How to use this method in java? Using a method in java?

hello there, i been having a problem in my grading program and i need some feedback some help setting up a method so it will return to its original value...wat i need to do is to remove the nested if expression for letter grade calculation from the main...

Answer:

Use a case statement.

Read more

Misiekj at Yahoo! Answers Mark as irrelevant Undo

Java program, use a public static method called 'longest'?

Hi there, Im only a beginner so be nice :) I have been asked to write a program which outputs the longest word (which i have done) But I need to set it in a 'public static method called longest' which takes 2 string paramiters and returns the longest...

Answer:

The method: public static String longest(String s1, String s2){ if(s1.length > s2.length){ return...

Read more

Tomas at Yahoo! Answers Mark as irrelevant Undo

How to use paint method in a JFrame in java?

I'm trying to do a java program in which a paint method is used in JFrame. But the message contained in msg is not shown. Please, give me the answer. Here is my program import java.awt.Graphics; import java.awt.Paint; import javax.swing.JFrame; import...

Answer:

import java.awt.BorderLayout; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing...

Read more

Rejaul at Yahoo! Answers Mark as irrelevant Undo

I have a bunch of Hadoop code implemented in Java that I would like to call from Python code. Instead of either re-implementing my Hadoop code in Python or my Python code in Java, what is the best method to use both types of code together?

It appears that Jype is an option. Is Jype the best solution for calling Hadoop code in Java from Python? Are there other options? Is anyone aware of any pitfalls of using Jype?

Answer:

I'd recommend jython.  I actually don't know java but I wanted to automate some tasks in Gephi, a graph...

Read more

Ross Kravitz at Quora Mark as irrelevant Undo

How to declare a boolean and use a method JAVA help!?

Hi, I want to know how do i declare a field as a boolean type in the class and set it to "false" in the constructor... also, for a method, how would i change this value from 'true' to 'false' please help, im new to java..thank you in advance...

Answer:

class BooleanTest { boolean isActive; public BooleanTest() { isActive = false; } // this will flip a...

Read more

Samantha at Yahoo! Answers Mark as irrelevant Undo

How to use method in java to square two numbers?

Write a method that takes two arguments: two integers. The integers are then squared, added and the result printed on the screen. Write a simple program to invoke this method. help please

Answer:

How about this... public class Test2 { public void compute(int x, int y) { System.out.println("...

Read more

Kevin V at Yahoo! Answers Mark as irrelevant Undo

Questions is how can we use if statements in writing our own method in java?

like i am doing 3 caculations in my own method with if statements but i am unable to do so. This is my own method that i have written public static double calculateFine (double velocity) { if ((velocity > 20) || (velocity < 31)) { double velocity...

Answer:

There's nothing wrong with your code, but your logic is a bit off. In the first if statement, you probably...

Read more

MM at Yahoo! Answers Mark as irrelevant Undo

Java help. What code/method should i use for this program to work?

i have this program it's kinda like a bank program i can deposit and withdraw. and at the same time, i can show my current balance. 1 is for deposit 2 is for withdraw 3 is for current balance and 0 is for Exit in 'Exit', the program shows the current...

Answer:

You need a datastore for Transaction. Datastore can be an array or it can be ArrayList<Transaction...

Read more

Alyssa at Yahoo! Answers Mark as irrelevant Undo

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.