Java trap with a basket --- First Day: Class and Access Control
1.
Abstract class name {
PRIVATE STRING NAME;
Public Abstract Boolean isstupidName (String Name) {}
}
What is wrong with the heroes?
2.
Public class something {
Void dosomething () {
Private string s = "";
INT L = S.LENGTH ();
}
}
Is it wrong?
3.
Abstract class something {
Private abstract string dosomething ();
}
It seems that there is nothing wrong?
4.
Public class something {
Public Int Addone (Final INT X) {
Return x;
}
}
This is more obvious.
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;
}
It is very similar to the above, it is about Final problem, is this wrong?
6.
Class Something {
INT I;
Public void dosomething () {
System.out.println ("i =" i);
}
}
Is there anything wrong? I can't see it.
7.
Class Something {
Final INT I;
Public void dosomething () {
System.out.println ("i =" i);
}
}
There is only one place with one of the above questions, that is, there is a final. Is this wrong?
8.
Public class something {
Public static void main (String [] args) {
Something s = new something ();
System.out.println ("s.dosomething () returns" DOSMETHING ());
}
Public string dosomething () {
Return "Do Something ...";
}
}
It looks perfect.
9.
Here, the file name of the Something class is called Othershing.java
Class Something {
Private static void main (string [] Something_to_do) {
System.out.println ("Do Something ...");
}
}
This seems to be obvious.
10.
The hardest question today:
Interface playable {
Void Play ();
}
Interface bounceable {
Void Play ();
}
Interface Rollable Extends Playable, Bounceable {
Ball ball = New Ball ("pingpang");
}
Class ball imports 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 ());
}
}
This error is not easy to find.