小编hem*_*nth的帖子

私有方法可以在java的类外部访问

我在网络bean中尝试了以下代码我期待错误,但我没有得到任何错误

class B {

    private void method() {
    }

    public static void main() {
        B b = new B();
        B c = new C();
        b.method();
        c.method();
    }
}

class C extends B {
}
Run Code Online (Sandbox Code Playgroud)

c.method()试图访问该方法时它应该显示错误,但在NetBeans它没有显示.请告诉我是什么错.

java

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

java中的异常处理

我试图运行以下代码,但我收到错误请澄清我的疑问

import java.util.*;

    class Except 
    { public class AlfaException extends Exception{}
      public static void main(String[] args)
       {

        int b;
        Scanner s=new Scanner(System.in);
          try
            { 
              b=s.nextInt();
            }
          catch(InputMismatchException ex)
               {
                 try
                     {
                        if(('b'> 67)&&('b'<83)){}
                     }
                 catch(AlfaException e){
                   throw new AlfaException("hello");
                    }         
                 System.out.println("error found");
               }
        }
    }  



 Except.java:20: non-static variable this cannot be referenced from a static cont
ext
               throw new AlfaException("hello");
                     ^
Run Code Online (Sandbox Code Playgroud)

1错误

java

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

重写方法不能抛出异常

在编译以下代码时我遇到了错误

    @Override
public void routeCustomerRequest (int choice) throws UnSupportedCustomerRequestException{
    //throw new UnsupportedOperationException("Not supported yet.");

    switch(choice)
    {
        case '1':
            System.out.println("1. Add a new Customer");
            break;
        default :
            throw  UnSupportedCustomerRequestException("hehehe");
    }
}

  // its constructor class is

public class UnSupportedCustomerRequestException extends Exception {
public UnSupportedCustomerRequestException(String bong){
    System.out.println(bong);
}
Run Code Online (Sandbox Code Playgroud)

}

它的界面是

   /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bankingappication;

/**
 *
 * @author Training
 */
public interface IBankingServices {
    public …
Run Code Online (Sandbox Code Playgroud)

java

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

标签 统计

java ×3