小编use*_*643的帖子

Java示例包含封装,多态和继承?

我需要使用Java生成一个具有所列出的面向对象编程特性的项目.

有人可以查看我的快速示例程序,以确认我了解这些特性是如何实现的,并且它们都是正确存在和完成的吗?

package Example;

public class Parent {

    private int a;
    public void setVal(int x){
        a = x;
    }
    public void getVal(){
        System.out.println("value is "+a);
    }
}

public class Child extends Parent{

    //private fields indicate encapsulation
    private int b;
    //Child inherits int a and getVal/setVal methods from Parent
    public void setVal2(int y){
        b = y;
    }
    public void getVal2(){
        System.out.println("value 2 is "+b);
    }
    //having a method with the same name doing different things
    //for different parameter types indicates overloading, …
Run Code Online (Sandbox Code Playgroud)

java polymorphism inheritance encapsulation

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

mysqldb cursor.close()在执行从文件读取的sql时抛出ProgrammingError:(2014,"命令不同步...")

作为更大调试工作的一部分,我使用mysqldb遇到了以下错误:

File "x.py" line x, in method
    cursor.close()
File "y.py" line 100, in close
    while self.nextset(): pass
File "z.py" line 137, in nextset
    self._waring_check()
...
Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in <bound method Cursor.__del__ of <MySQLdb.cursor.Cursor object at 0x000002373198>> ignored
Run Code Online (Sandbox Code Playgroud)

我的代码的相关部分如下:

connection = mysqldb.connect('localhost', 'root', 'password', 'db')
cursor = connection.cursor()
file = open(filename, 'r')
sql = s = " ".join(file.readlines)
cursor.execute(sql)
cursor.close()
...
Run Code Online (Sandbox Code Playgroud)

在我进入其他任何东西之前,会在cursor.close()行上抛出错误,这对我来说没有任何意义......有人知道我做错了什么吗?在所有代码中只使用了一个线程.

python sql connection cursor mysql-python

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

tkinter:更改特定菜单项的前景色

使用 TKinter,是否可以仅更改菜单中某些项目的文本颜色?我想让不太受欢迎的项目具有较少的对比度,以便用户可以快速找到最常用的项目。到目前为止,我只找到了Menu'sforeground选项,它改变了所有东西(不是特定项目)的颜色,或者让特定项目的state选项disabled改变颜色,但它们仍然应该能够被点击来做一些事情。有小费吗?我希望有一种方法可以使用MenuorMenubutton类来做到这一点,而不必为这个功能从头开始重新实现菜单。

python user-interface menu tkinter colors

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