JAVA 基础心得

float f=1.3;
Will not compile because the default type of a number with a floating point

component is a double. This would compile with a cast as in

float f=(float) 1.3


A class that contains an abstract method must itself be declared as abstract.

It may however contain non abstract methods. Any class derived from an

abstract class must either define all of the abstract methods or be declared

abstract itself.

 

 

1) Methods cannot be overriden to be more private
2) static methods can be overloaded
3) private methods can be overloaded

 

 

 

class Base {}
class Sub extends Base {}
class Sub2 extends Base {}
public class CEx{ 
  public static void main(String argv[])
{ Base b=new Base(); 
Sub s=(Sub) b;    }
}
3) Runtime Exception
 

我们要知道wait()跟sleep()本质上来说是绝对不一样的。sleep()使得一个进程进入睡

眠状态,但是线程所占有的资源并没有释放。比如,你在synchronized模块(加函数锁

或者对象锁)里面调用了sleep(),虽然线程睡着了而且没有使用资源,但是它依然保存

着锁,别的线程依然无法调用相关的synchronized模块。而wait()就不同,它实际上了

放弃了锁,将资源贡献出来,而使自己暂时离岗。这个离岗状态一直会持续到“boss“

(其他的线程)调用了notify(),通知线程继续回来工作。

 

class Base{
public void amethod(int i) { }
}

public class Scope extends Base{
 public static void main(String argv[]){ }

public void amethod(int i) throws Exception{}
}


s=abcd
s.substring(1,3));  结果为:bc

 

The | is known as the Or operator, you could think of it as the either/or

operator. Turning the numbers into binary gives
4=100
3=011
For each position, if either number contains a 1 the result will contain a

result in that position. As every position contains a 1 the result will be
111
Which is decimal 7.
所以3|4=7

 


**

public class Pass{ 
  static int j=20;  

 public static void main(String argv[])
{ int i=10;
 Pass p = new Pass();
 p.amethod(i); 

System.out.println(i); 
System.out.println(j);

   } 


  public void amethod(int x){
 x=x*2; 
 j=j*2;  
 }
}
结果为i=10,j=40

when a parameter is passed to a method the method receives a copy of the

value. The method can modify its value without affecting the original copy.

 

**
class Base{ 
  Base(){ 
int i = 100;
 System.out.println(i);    }
}


public class Pri extends Base{   

 public static void main(String argv[]){
 int i = 200;   //子类的相同名字的变量复盖父类的变量
 Pri p = new Pri(); 

System.out.println("sub="+i);    }}
结果sub=200


****
 class Base{
 private void a(){
  
  System.out.println("sdfasf");  
 }

class Pri extends Base{
  public int a(){//子类的overridder的权限不可比父类低,只可高  //返回值

不可为int,要和父类一样为void
   int i;
  System.out.println("sdfasf");
  return i;
 }

 

**
明为static的方法有以下几条限制:

◆它们仅能调用其他的static 方法。
◆它们只能访问static数据。
◆它们不能以任何方式引用this 或super

**
A final method cannot be ovverriden in a sub class,

**
public class Arg{
static String[] MyArg; 
public static void main(String argv[]){  
 MyArg=argv;    //数据可以直接给值
 System.out.println(MyArg[1]); 

**
  public void amethod(int i, String s){}
  public void amethod(String s, int i){}
为不同的方法 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值