Java: class , objects
Java: class , objects
1 Inheritance(¼Ì³Ð)µÄ¹Ø¼ü×Öextends
class MountainBike extends Bicycle {
}
µ«ÊDz»ÄܶàÖØ¼Ì³Ð¡£²»¹ý¿ÉÒÔͨ¹ýimplements¶à¸öinterfaceÀ´ÊµÏÖÀàËÆµÄ¶«Î÷
2 interface
interface Bicycle {
void changeCadence(int newValue); // wheel revolutions per minute
void changeGear(int newValue);
void speedUp(int increment);
void applyBrakes(int decrement);
}
class ACMEBicycle implements Bicycle {
// remainder of this class implemented as before
}
¿ÉʵÏÖ(implements)¶à¸öinterface
class MyClass extends MySuperClass implements YourInterface {
//field, constructor, and method declarations
}
means that MyClass is a subclass of MySuperClass and that it implements the YourInterface interface
3 package
A package is a namespace that organizes a set of related classes and interfaces.
4 Access Modifier
public, private, protected
public class Bicycle {
private int cadence;
public int aag;
public void test();
}
ÿ¸öfield»òmethod¶¼±ØÐëµ¥¶ÀÐÞÊÎ
Access Levels
ModifierClassPackageSubclassWorld
public
Y
Y
Y
Y
protected
Y
Y
Y
N
no modifier
Y
Y
N
N
private
Y
N
N
N
Ô¼¶¨£º
class Ãû×ֵĵÚÒ»¸ö×Öĸ´óд; methodµÚÒ»¸öwordÊǶ¯´Ê
5 Constructors
The compiler automatically provides a no-argument, default constructor for any class without constructors.
This default constructor will call the no-argument constructor of the superclass.
6 method & parameter
The Java programming language doesn't let you pass methods into methods. But you can pass an object into a method and then invoke the object's methods.
can Returning a Class or Interface??
7 this : current object
public class Point {
public int x = 0; //field¿ÉÒÔÕâÑù³õʼ»¯
public int y = 0;
Ïà¹ØÎĵµ£º
ÏßÐÔ±í£¬Á´±í£¬¹þÏ£±íÊdz£ÓõÄÊý¾Ý½á¹¹£¬ÔÚ½øÐÐJava¿ª·¢Ê±£¬JDKÒѾΪÎÒÃÇÌṩÁËһϵÁÐÏàÓ¦µÄÀàÀ´ÊµÏÖ»ù±¾µÄÊý¾Ý½á¹¹¡£ÕâЩÀà¾ùÔÚjava.util°üÖС£±¾ÎÄÊÔͼͨ¹ý¼òµ¥µÄÃèÊö£¬Ïò¶ÁÕß²ûÊö¸÷¸öÀàµÄ×÷ÓÃÒÔ¼°ÈçºÎÕýȷʹÓÃÕâЩÀà¡£
Collection
©ÀList
©¦©À ......
oracle
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
String user="scott";
String password="tiger";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_S ......
1¡¢set¼¯ºÏÊÇ×î¼òµ¥µÄÒ»ÖÖ¼¯ºÏ£¬¼¯ºÏÖв»°´Ö¸¶¨µÄ·½Ê½ÅÅÐò£¬²¢ÇÒûÓÐÖØ¸´¶ÔÏó¡£
2¡¢set½Ó¿ÚÖ÷ÒªÓÐÁ½¸öʵÏÖÀࣺHashSetºÍTreeSet
(1)HashSet:Êǰ´ÕÕ¹þÏ£Ëã·¨À´½øÐдæÈ¡¼¯ºÏÖеĶÔÏ󣬴æÈ¡µÄËٶȱȽϿ졣
(2)TreeSet£ºÊµÏÖÁËSortedSet½Ó¿Ú£¬¾ßÓÐÅÅÐòµÄ¹¦ÄÜ¡£
3¡¢HashSetÀàÊǰ´ÕÕ¹þÏ£Ëã·¨À´´æÈ¡ ......
1.1 ²»ÓÃnew¹Ø¼ü´Ê´´½¨ÀàµÄʵÀý
ÓÃnew¹Ø¼ü´Ê´´½¨ÀàµÄʵÀýʱ£¬¹¹Ô캯ÊýÁ´ÖеÄËùÓй¹Ô캯Êý¶¼»á±»×Ô¶¯µ÷Óᣵ«Èç¹ûÒ»¸ö¶ÔÏóʵÏÖÁËCloneable½Ó¿Ú£¬ÎÒÃÇ¿ÉÒÔµ÷ÓÃËüµÄclone()·½·¨¡£clone()·½·¨²»»áµ÷ÓÃÈκÎÀ๹Ô캯Êý¡£
ÔÚʹÓÃÉè¼ÆÄ£Ê½£¨Design Pattern£©µÄ³¡ºÏ£¬Èç¹ûÓÃFactoryģʽ´´½¨¶ÔÏó£¬Ôò¸ÄÓÃclone()·½·¨´´½¨Ðµ ......
ºÃ¾ÃÁË£¬¶¼ÏëÏòѧϰJAVAµÄÐÂÈËдµã¶«Î÷£¬ÒòΪÎÒʵÔÚ¿´²»ÏÂÈ¥ÁË£¬¿´²»ÏÂÈ¥ºÜ¶àÎóµ¼JAVAѧϰÕߵĹ۵㣬±é¼°ÌìÏ£¡ÍøÂçÈúõĶ«Î÷Á÷ÐУ¬¿ÉÊÇÍùÍùÒ²ÈôíµÄ¶«Î÷³öÏֵĴÎÊý¶àÁ˱äµÄºÃÏñÕýÈ·ÁË£¬ÈýÈ˳ɻ¢£¬Ö¸Â¹ÎªÂíËÆºõÔÚÍøÂçÀï¸ü¼ÓÈÝÒ×·¢Éú£¬ºÃÁË·Ï»°²»Ëµ£¬Çë¿´ÎÒϸϸÏòÄãµÀÀ´¡£
ÃØÃÜÒ»£¬Ñ§Ï°JAVAºÃδ±Ø¿ÉÒÔÕÒµ½JA ......