object oriented programming (面向对象)

一、类与对象
 

类:class,例如 animal class。指代一个笼统意义上的大类

对象: object, 例如 animal class会有 ant object,dog object。对象指代大类中的小类。

如何构造 类:

 

如何创建对象:

source code: Animal ant=new Animal.

Animal ant=new Animal.



二、Static vs Final (静态与常量)



1.Static Attribute &Method (静态变量与方法)

静态属性

  • 表示只属于类,不属于对象
  • 使用时用类去调动

源代码

class Foo {
    public static void method() {
        System.out.println("in Foo");
    }
}
 
class Bar extends Foo {
    public static void method() {
        System.out.println("in Bar");
    }
}
class Test {
public static void main(String[] args) {
 
        Foo.method();// 输出: in Foo , 使用 foo 类名调用
        Bar.method();//输出:in Bar,使用 bar类名调用
    }
}



2.Final

  • 属于最终形态,不可以赋值
  • final 方法不可以重写
  • final class string 不可以继承

代码块和静态代码块的使用

  • public class User {
        String name;
        final int id=1001;
        static int staticnum;
        static  final int stafinalnum=1000;
    
        {//代码块:创建对象时执行,每次创建对象都会执行
            System.out.println("代码块");
        }
        static {//静态代码块:类初次加载时执行
            stafinalnum=100;
            System.out.println("静态代码块");
        }
    
        public User(){
            System.out.println("构造方法");
        }
        public User(String name){
            this.name=name;
        }
        
        // 静态方法
        public static void getName(){
            System.out.println("静态方法 ");
        }
    
        public void login(){
            System.out.println("普通方法");
        }
    
        public static void main(String[] args) {
            User.getName();
    
            User user = new User();
            user.login();
          
        }
    }
    

输出:

​

静态代码块
静态方法
    
代码块
构造方法
普通方法


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Title: R Object-Oriented Programming Author: Kelly Black Length: 190 pages Edition: 1 Language: English Publisher: Packt Publishing Publication Date: 2014-10-23 ISBN-10: 1783986689 ISBN-13: 9781783986682 A practical guide to help you learn and understand the programming techniques necessary to exploit the full power of R About This Book Learn and understand the programming techniques necessary to solve specific problems and speed up development processes for statistical models and applications Explore the fundamentals of building objects and how they program individual aspects of larger data designs Step-by-step guide to understand how OOP can be applied to application and data models within R Who This Book Is For This book is designed for people with some experience in basic programming practices. It is also assumed that they have some basic experience using R and are familiar using the command line in an R environment. Our primary goal is to raise a beginner to a more advanced level to make him/her more comfortable creating programs and extending R to solve common problems. In Detail R is best suited to produce data and visual analytics through customizable scripts and commands, instead of typical statistical tools that provide tick boxes and drop-down menus for users. The book is divided into three parts to help you perform these steps. It starts by providing you with an overview of the basic data types, data structures, and tools available in R that are used to solve common tasks. It then moves on to offer insights and examples on object-oriented programming with R; this includes an introduction to the basic control structures available in R with examples. It also includes details on how to implement S3 and S4 classes. Finally, the book provides three detailed examples that demonstrate how to bring all of these ideas together. Table of Contents Chapter 1. Data Types Chapter 2. Organizing Data Chapter 3. Saving Data and Printing Results Chapter 4. Calculating Probabilities and Random Numbers Chapter 5. Character and String Operations Chapter 6. Converting and Defining Time Variables Chapter 7. Basic Programming Chapter 8. S3 Classes Chapter 9. S4 Classes Chapter 10. Case Study – Course Grades Chapter 11. Case Study – Simulation
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值