I am a newbie and learning methods and constructors. Questions as follow
- When I run the below program in Eclipse, I am prompted an error that I can declare main method as static.
public class Mouse
{
double version;
String model;
Mouse(double v, String m)
{
version = v;
model = m;
}
void display()
{
System.out.printf("Version is ", +version);
System.out.printf("Model is ",model);
}
}
class DemoMouse
{
public static void main(String[] args) {
{
Mouse m = new Mouse(5.1, "Logitech");
m.display();
}
}
- When I am forced to remove static from main and make DemoMouse as static, I dont get the full output.I get out put is Version is Model is. I expect the out put as
*Version is 2.4
Model is Logitech*
package test;
public class Mouse
{
double version;
String model;
Mouse(double v, String m)
{
version = v;
model = m;
}
void display()
{
System.out.printf("Version is ", +version);
System.out.printf("Model is ",model);
}
}
static class DemoMouse
{
public void main(String[] args) {
{
Mouse m = new Mouse(5.1, "Logitech");
m.display();
}
}