Java code error

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.