java,method,contructor,class,属性 程序
2016-07-07 19:28
531 查看
public class Mobile {//class public String brand;//属性 public是修饰符 public int weight;//属性 public String getBrand (){//method 方法 String 是返回值类型,一般方法 和构造方法的不同之处。 return brand; } public Mobile(String brand,int weight){//constructor 构造方法 this.brand = brand; this.weight = weight; } public static void main(String[] args)//main method,程序入口 { //Mobile mobile = new Mobile();//无参构造器 Mobile mobile = new Mobile("samsumg",200);//有参数的对象创建。构造器 System.out.println("手机品牌"+mobile.getBrand()); System.out.println(mobile.brand);//对象方法和对象属性的访问用 点 操作符 System.out.println(mobile.weight); } }
相关文章推荐
- 使用maven一步一步构建spring mvc项目
- eclipse反编译插件jd-eclipse
- 在myeclipse10.6版本中,安装git插件以及正确导入项目的问题
- 【爬虫】WebMagic结合Spring mvc爬取数据进行存储
- java的内存分配
- myeclipse配置JDK
- SpringMVC+Maven+MyBatis项目JSP页面分页处理
- Spring之Spring IOC(概念、原理、实践)
- java泛型
- Struts2学习之常用配置及action接收参数
- 代理模式浅析
- Spring IOC理解
- Java泛型学习一
- 几种任务调度的 Java 实现方法与比较Timer,ScheduledExecutor,Quartz,JCronTab
- 几种任务调度的 Java 实现方法与比较Timer,ScheduledExecutor,Quartz,JCronTab
- 认识Java数组(一)
- java,spring mvc,文件下载
- java random.nextInt的坑
- ThreadLocal
- java反射学习总结