小编pra*_*abh的帖子

在命令提示符下运行时ClassNotFoundException

我是java的新手,并试图运行一个简单的计算量的代码.代码如下:

package chapter6;

class Box {

    double width;
    double height;
    double depth;
}
Run Code Online (Sandbox Code Playgroud)
package chapter6;

    public class BoxDemo {

        public static void main(String[] args) {

            Box myBox = new Box();
            double vol;

            myBox.depth = 1;
            myBox.height = 2;
            myBox.width = 3;

            vol = myBox.depth * myBox.height * myBox.width ;        

            System.out.println("Volume: " + vol);
        }

    }
Run Code Online (Sandbox Code Playgroud)

我能够从eclipse运行代码,但是当我尝试在命令提示符下运行代码时,我得到错误:

C:\Prabhjot\Java\CompleteRefence\build\classes>java BoxDemo.class
Exception in thread "main" java.lang.NoClassDefFoundError: BoxDemo/class
Caused by: java.lang.ClassNotFoundException: BoxDemo.class
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at …
Run Code Online (Sandbox Code Playgroud)

java

3
推荐指数
2
解决办法
8596
查看次数

java中的新关键字

java新手,仍然在努力使用新的关键字和继承:

public class A1 {
    void a_method (){
        System.out.println("Inside A1 method");
    }
}
Run Code Online (Sandbox Code Playgroud)
public class A2 extends A1{
    void a_method(){
        System.out.println("Inside A2 method");
    }
}
Run Code Online (Sandbox Code Playgroud)
public class TestA1A2 {

    public static void main(String[] args) {

        A1 a1 = new A1();
        A1 a2 = new A2();  //not sure if it created object of A1 or A2
        A2 a3 = new A2();

        a1.a_method();
        a2.a_method();
        a3.a_method();

    }
}
Run Code Online (Sandbox Code Playgroud)

我正在努力理解新关键字,如果在上面的代码中:

A1 a2 = new A2();  //not sure if it created object of A1 or …
Run Code Online (Sandbox Code Playgroud)

java inheritance

3
推荐指数
1
解决办法
607
查看次数

Javascript 中无中断切换

drink = 'beer'

switch(drink){
    case 'beer':
    case 'whiskey':
        console.log('The drink is BEER or WHISKEY');
    case 'juice':
        console.log('The drink is JUICE');
    default:
        console.log('Nothing to drink');
}
Run Code Online (Sandbox Code Playgroud)

对于上面的代码,为什么我会在控制台中收到所有三个消息?有人可以解释一下吗?如果没有break,我期望打印案例消息和默认消息,但为什么“juice”相关消息也出现在控制台中?

javascript switch-statement

1
推荐指数
1
解决办法
4854
查看次数

变量定义为私有

我仍然是Java的新手.我的问题可能非常基本.

我有一个班级超级班,

package chapter8;

public class Box {

    double width;
    private double height;
    private double depth;

    Box(double w, double h, double d) {
        width = w;
        height = h;
        depth = d;
    }

    double volume() {
        return width * height * depth;
    }
}
Run Code Online (Sandbox Code Playgroud)

BoxWeight是Box超类的子类:

package chapter8;

public class BoxWeight extends Box {

    double weight;

    BoxWeight(double w, double h, double d, double m){
        super(w, h, d);
        weight = m;
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我主要在DemoBoxWeight

package chapter8;

public class DemoBoxWeight {

    public static …
Run Code Online (Sandbox Code Playgroud)

java

-2
推荐指数
1
解决办法
112
查看次数

标签 统计

java ×3

inheritance ×1

javascript ×1

switch-statement ×1