Java code error
1.
Abstract class Name {
Private String name;
Public abstract boolean isStupidName (String name ){}
}
What are the errors?
-------------- The abstract method in the abstract class does not have a method body, ending with a semicolon
2.
Public class Something {
Void doSomething (){
Private String s = "";
Int l = s. length ();
}
}
-------------- The access modifier cannot be used in the Method
3.
Abstract class Something {
Private abstract String doSomething ();
}
--------------- Private and abstract cannot be used together.
4.
Public class Something {
Public int addOne (final int x ){
Return ++ x;
}
}
---------------- When the final modified scalar is used as a parameter, it can be applied once, but its value cannot be changed
5.
Public class Something {
Public static void main (String [] args ){
Other o = new Other ();
New Something (). addOne (o );
}
Public void addOne (final Other o ){
O. I ++;
}
}
Class Other {
Public int I;
}
----------------- Yes (the reference of O has not changed, but it only calls its attributes)
6.
Class Something {
Int I;
Public void doSomething (){
System. out. println ("I =" + I );
}
}
What's wrong?
------------------ Yes, the member variables have defaultValue;
7.
Class Something {
Final int I;
Public void doSomething (){
System. out. println ("I =" + I );
}
}
------------------- The final modified member variable does not have defavaluvalues
8.
Public class Something {
Public static void main (String [] args ){
Something s = new Something ();
System. out. println ("s. doSomething () returns" + doSomething ());
}
Public String doSomething (){
Return "Do something ...";
}
}
---------------------- The main method is static and cannot be called directly.
9.
Here, the name of the Something class is OtherThing. java.
Class Something {
Private static void main (String [] something_to_do ){
System. out. println ("Do something ...");
}
}
---------------------- Yes. Non-public class names can be different from file names.
10.
Interface {
Int x = 0;
}
Class B {
Int x = 1;
}
Class C extends B implements {
Public void pX (){
System. out. println (x );
}
Public static void main (String [] args ){
New C (). pX ();
}
}
------------------------- The call is ambiguous.
11.
Interface Playable {
Void play ();
}
Interface Bounceable {
Void play ();
}
Interface Rollable extends Playable, Bounceable {
Ball ball = new Ball ("PingPang ");
}
Class Ball implements Rollable {
Private String name;
Public String getName (){
Return name;
}
Public Ball (String name ){
This. name = name;
}
Public void play (){
Ball = new Ball ("Football ");
System. out. println (ball. getName ());
}
}
---------------------------- The default member variable of the interface is public static final, so ball = new Ball ("Football"); the reference is changed, so it is incorrect.