JAVA face Test

Source: Internet
Author: User

1. Do not allow access to super.super.xxx why?

Super is a private member of the current class , representing the parent class,
Super.super means to access private members of the parent class , which is impossible to access.

2.







Public     class pp
... {
intx=5, y=Ten;
voidSetv (intA,intb
...{
X=A;
Y=b;
}
intget_1 ()
...{
return x+y;
}
intget_2 ()
...{
return x-y;
}
Public   classTestextendspp
...{
inty;
Test (inta)...{
Y=A;
}
Sety (intA,intb)
...{
int get_2 () ... {
return y;
}
}
/**//*
1. with PP a1=new pp (), the contents of a1.get_1 () are _________
2. PP A1=new pp () after A1.setv (10.10) a1.get_2 () content _________
3. After using Test a1=new test (1), the contents of a1.get_1 () are ____________
4. After using Test a1=new test ( -1), A1.setv (5.5), a1.get_2 content ____________
*/3. The object class has a Clone method, but object does not implement the Cloneable interface, why? For a class that does not implement cloneable, it is possible to implement some basic value copying operations with the Clone method inherited from the object class, is it possible to say that the Clone method does not verify that the object belongs to the cloneable type?

1, 15
2, 0
3, 6
4, 6

The > > > Object class has a Clone method, but object does not implement the Cloneable interface.
The Clone method in the object class is protected, it is not cloneable in the province, just want to inherit the class can easily implement Cloneable interface

> > > For a class that does not implement cloneable, it is possible to implement some basic value-copying operations with the Clone method inherited from the object class, Is it possible to say that the Clone method does not verify that the object belongs to the cloneable type?
Yes, implementing the Clone method does not mean that this class is the cloneable type.

The protected clone method can only be invoked within the class, but with the implementation of the Cloneable interface, it is possible to use the Copy method not just within the class.

4.Which of the following statements about declaration are true?





A. Declaration of primitive types such as Boolean, Byte and so in does not allocate memory Spaces for the variable.





B. Declaration of primitive types such as Boolean, Byte and so on allocates memory spaces for The variable.





C. Declaration of nonprimitive types such as String, Vector and so in does not allocate memo Ry spaces for the object.





D. Declaration of nonprimitive types such as String, Vector ans so on allocates memory spaces For the object.


1, Global variables:
When declaring a simple variable, the system allocates space to it in stack (stacks) and gives a default value;
When you declare an object, the system assigns him a pointer to an object in the stack, but only points to null, not the memory space of the object.
2, Local variables:
The Declaration allocates space in the stack (except that the object is still assigned the pointer to the object), and the default system is not initialized, so it can only be initialized before it can be used.

As can be seen from the above two points, BC is correct.

5. There are about 100,000 rows of data in a text file, one row per data (the data is an integer). Requirements: Count the total number of rows and find the integer that appears most frequently.

People help, the key is how to find the number of the most frequent







Package test;

Import java.io. * ;
Import java.util.ArrayList;

Public     class Testarray ... {

/**//*


* Public Object []getlist () {//get array!


* try{ArrayList list=new ArrayList ();


* BufferedReader in =


* New BufferedReader (New FileReader ("D:test"));


* String str;


* IF ((Str=in.readline ())!=null) {


* List.add (STR);


*     }


* return List.toarray ();


*


*}catch (Exception e) {


* E.printstacktrace ();


* return null; }


*       }


*/
Publicobject[] GetList ()...{//Test Array
string[] BB=   Newstring[ A];
for   (intI=   0; I<bb.length; I++)   ...{
Bb[i] = string.valueof ((int) (Math.random () * 50 ));
}
returnBB;
}

Public   intGetSize ()...{// statistic total number of rows
object[] o = getlist ();
return o.length;
}

Public   int[] Getmaxsameno ()...{//find the array that appears most frequently

Object o[]=getlist ();

intno[]=   New   int[O.length];
for   (intI=   0; I<o.length; I++)   ...{
No[i] = integer.parseint ((String) o[i]);

}
Java.util.Arrays.sort (no);//Array Sorting
for   (intI=   0; I<no.length; I++)   ...{
System.out.println ( "array[ " + i + c10> "]= " + no[i]);
}

intMaxsum=getsum (no);//the number that appears most often appears several times
returngetInt (No, maxsum);//find the number that appears most frequently

}

Public   intGetsum (int[] No)...{//This method returns the number of occurrences that appear the most times!
ArrayList sumlist=   NewArrayList ();
intsum=   1;
for   (intI=   0; I<No.length-   1; I++)   ...{
if(No[i]==No[i+   1])   ...{
Sum+ +; // Pro Two equal counters +1
}   Else   ...{
// not equal to join in the set
Sumlist.add (sum);
// counter Reset continues to compare
sum = 1;
Continue ;
}
}
intMax=   0;
for   (intI=   0; I<sumlist.size (); I++)   ... {// This loop takes out the largest number in the collection!
if (Integer.parseint (Sumlist.get (i). toString ()) > max) ... {
Max = integer.parseint (Sumlist.get (i). toString ());
}
}
returnMax
}

Public   int[] GetInt (int[] No,inta)...{//This method returns an array with a number of occurrences, possibly with multiple numbers appearing the same number of times, so the array is returned
ArrayList sumlist=   NewArrayList ();
intsum=   1;
for   (intI=   0; I<No.length-   1; I++)   ...{
if(No[i]==No[i+   1])   ...{
Sum+ +;
}   Else   ...{
if(Sum==a)...{
Sumlist.add (No[i]);
System.out.println (No[i] + " appeared altogether " + A  + " times!" ");
Sum=1;
Continue ;
}   Else   ...{
Sum = 1;
Continue ;
}

}
}
intaa[]=   New   int[Sumlist.size ()];
for   (intI=   0; I<aa.length; I++)   ...{
Aa[i] = integer.parseint ((Sumlist.get (i). toString ()));
}
returnAA;

}

/** *//**
* @param args
*/
Public   Static   voidMain (string[] args)...{
//TODO automatically generate method stubs
Testarray Test=   NewTestarray ();
intCount=test.getsize ();
System.out.println ("there are altogether"   +Count+   "record!");
int[] Max=Test.getmaxsameno ();
System.out.println ("the maximum number of occurrences is:");
for   (intI=   0; I<max.length; I++)   ...{
System.out.print (Max[i] + ", ");
}

}

}






<
Related Article

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.