{"id":3058,"date":"2011-11-03T12:02:56","date_gmt":"2011-11-03T12:02:56","guid":{"rendered":"https:\/\/www.techopedia.com\/definition\/class\/"},"modified":"2021-08-24T20:22:44","modified_gmt":"2021-08-24T20:22:44","slug":"class","status":"publish","type":"definition","link":"https:\/\/www.techopedia.com\/definition\/3214\/class-java","title":{"rendered":"Class"},"content":{"rendered":"

What Does Class Mean?<\/span><\/h2>\n

A class \u2014 in the context of Java \u2014 is a template used to create objects and to define object data types and methods.<\/p>\n

Classes are categories, and objects are items within each category.<\/p>\n

All class objects should have the basic class properties.<\/p>\n

Core properties include the actual attributes\/values and methods that may be used by the object.<\/p>\n

Techopedia Explains Class<\/span><\/h2>\n

A class in Java is a logical template to create objects that share common properties and methods.<\/p>\n

Hence, all objects in a given class will have the same methods or properties.<\/p>\n

For example: in the real world, a specific cat is an object of the \u201ccats\u201d class. All cats in the world share some characteristics from the same template such as being a feline, having a tail, or being the coolest of all animals.<\/p>\n

In Java, the \u201cCat\u201d class is the blueprint from which all individual cats can be generated that includes all cat characteristics, such as race, fur color, tail length, eyes shape, etc.<\/p>\n

So, for example, you cannot create a house from the cat class, because a house must have certain characteristics \u2014 such as having a door, windows and a roof \u2014 and none of these object properties can be found in the cat class.<\/p>\n

A class declaration is made up of the following parts:<\/p>\n

    \n
  • \n

    Modifiers<\/p>\n<\/li>\n

  • \n

    Class name<\/p>\n<\/li>\n

  • \n

    Superclass (the name of a class\u2019 parent, if available)<\/p>\n<\/li>\n

  • \n

    Implemented Interfaces (if any)<\/p>\n<\/li>\n

  • \n

    Appropriate Keywords depending on whether the class extends from a Superclass and\/or implements one or more interface<\/p>\n<\/li>\n

  • \n

    Class body within curly brackets {}<\/p>\n<\/li>\n<\/ul>\n

    Constructors are used to create and initialize new objects in a class. Every class must have a constructor \u2014 either a default one provided by the Java compiler or a new one written for that class.<\/p>\n

    The constructor is invoked every time a new object is built, but a class may have multiple constructors. It is used to assign default values to each class\u2019 variable to create a fully formed object. All the variables that define both the class and the objects (tail length, race, fur, etc.) are that class\u2019 fields. In the \u201cCat\u201d class, you can\u2019t imagine a physically existing cat that has no fur, height, weight, etc. The constructor, therefore, initializes an object with a set of standardly assigned values that could be set by the programmer or by Java (default constructor).<\/p>\n

    To implement the behavior of the class and its objects, methods are used. For example, \u201cplaying with a string\u201d or \u201cmeowing to request food at 4:00 AM\u201d are methods.<\/p>\n

    Three Different Types of Variables<\/span><\/h2>\n

    Local variables<\/h3>\n

    Temporary variables defined inside methods. They are declared and initialized within that method, and will be made eligible for garbage collection once the method is completed.<\/p>\n

    For example: in the method \u201cplaying with a string,\u201d the string is a local variable.<\/p>\n

    Instance variables<\/h3>\n

    They are variables that are inherent to an object and that can be accessed from inside any method, constructor or block.<\/p>\n

    They are destroyed when the object is destroyed.<\/p>\n

    Class variables<\/h3>\n

    Class variables or static variables are declared with the static keyword in a class. They are similar to instance variables, but they are created when the program starts and destroyed when the program stops.The main difference with instance variables is in what scope they are available. A class variable is accessible from an object instance, while an instance variable is not accessible from a class method.<\/p>\n","protected":false},"excerpt":{"rendered":"

    What Does Class Mean? A class \u2014 in the context of Java \u2014 is a template used to create objects and to define object data types and methods. Classes are categories, and objects are items within each category. All class objects should have the basic class properties. Core properties include the actual attributes\/values and methods […]<\/p>\n","protected":false},"author":7813,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_acf_changed":false,"_lmt_disableupdate":"","_lmt_disable":"","om_disable_all_campaigns":false,"footnotes":""},"definitioncat":[273,244],"class_list":["post-3058","definition","type-definition","status-publish","format-standard","hentry","definitioncat-devops","definitioncat-programming-languages"],"acf":[],"yoast_head":"\nWhat is a Class? - Definition from Techopedia<\/title>\n<meta name=\"description\" content=\"This definition explains the meaning of Class and why it matters.\" \/>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Class\" \/>\n<meta property=\"og:description\" content=\"This definition explains the meaning of Class and why it matters.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.techopedia.com\/definition\/3214\/class-java\" \/>\n<meta property=\"og:site_name\" content=\"Techopedia\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/techopedia\/\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-24T20:22:44+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@techopedia\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.techopedia.com\/definition\/3214\/class-java#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.techopedia.com\/definition\/3214\/class-java\"},\"author\":{\"name\":\"Margaret Rouse\",\"@id\":\"https:\/\/www.techopedia.com\/#\/schema\/person\/f5dd538e31ee352d105b8af36c4268a5\"},\"headline\":\"Class\",\"datePublished\":\"2011-11-03T12:02:56+00:00\",\"dateModified\":\"2021-08-24T20:22:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.techopedia.com\/definition\/3214\/class-java\"},\"wordCount\":570,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.techopedia.com\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.techopedia.com\/definition\/3214\/class-java#respond\"]}],\"articleSection\":\"\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.techopedia.com\/definition\/3214\/class-java\",\"url\":\"https:\/\/www.techopedia.com\/definition\/3214\/class-java\",\"name\":\"What is a Class? - Definition from Techopedia\",\"isPartOf\":{\"@id\":\"https:\/\/www.techopedia.com\/#website\"},\"datePublished\":\"2011-11-03T12:02:56+00:00\",\"dateModified\":\"2021-08-24T20:22:44+00:00\",\"description\":\"This definition explains the meaning of Class and why it matters.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.techopedia.com\/definition\/3214\/class-java#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.techopedia.com\/definition\/3214\/class-java\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.techopedia.com\/definition\/3214\/class-java#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.techopedia.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DevOps\",\"item\":\"https:\/\/www.techopedia.com\/topic\/324\/devops\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Programming Languages\",\"item\":\"https:\/\/www.techopedia.com\/topic\/89\/programming-languages\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Term\",\"item\":\"https:\/\/www.techopedia.com\/definition\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Class\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.techopedia.com\/#website\",\"url\":\"https:\/\/www.techopedia.com\/\",\"name\":\"Techopedia\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.techopedia.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.techopedia.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.techopedia.com\/#organization\",\"name\":\"Techopedia\",\"url\":\"https:\/\/www.techopedia.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techopedia.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.techopedia.com\/wp-content\/uploads\/2025\/02\/techopedia-light-logo.svg\",\"contentUrl\":\"https:\/\/www.techopedia.com\/wp-content\/uploads\/2025\/02\/techopedia-light-logo.svg\",\"caption\":\"Techopedia\"},\"image\":{\"@id\":\"https:\/\/www.techopedia.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/techopedia\/\",\"https:\/\/x.com\/techopedia\",\"https:\/\/www.linkedin.com\/company\/techopedia\/\",\"https:\/\/www.youtube.com\/c\/Techopedia\"],\"publishingPrinciples\":\"https:\/\/www.techopedia.com\/about\/editorial-policy\",\"ownershipFundingInfo\":\"https:\/\/www.techopedia.com\/about\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.techopedia.com\/#\/schema\/person\/f5dd538e31ee352d105b8af36c4268a5\",\"name\":\"Margaret Rouse\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techopedia.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.techopedia.com\/wp-content\/uploads\/2023\/02\/margaret-rouse-headshot.jpeg\",\"contentUrl\":\"https:\/\/www.techopedia.com\/wp-content\/uploads\/2023\/02\/margaret-rouse-headshot.jpeg\",\"caption\":\"Margaret Rouse\"},\"description\":\"Margaret is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other\u2019s highly specialized languages.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/margaretrouse\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/@techdefinitions\"],\"knowsAbout\":[\"Technology Expert\"],\"url\":\"https:\/\/www.techopedia.com\/contributors\/margaret-rouse\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"What is a Class? - Definition from Techopedia","description":"This definition explains the meaning of Class and why it matters.","robots":{"index":"noindex","follow":"follow"},"og_locale":"en_US","og_type":"article","og_title":"Class","og_description":"This definition explains the meaning of Class and why it matters.","og_url":"https:\/\/www.techopedia.com\/definition\/3214\/class-java","og_site_name":"Techopedia","article_publisher":"https:\/\/www.facebook.com\/techopedia\/","article_modified_time":"2021-08-24T20:22:44+00:00","twitter_card":"summary_large_image","twitter_site":"@techopedia","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.techopedia.com\/definition\/3214\/class-java#article","isPartOf":{"@id":"https:\/\/www.techopedia.com\/definition\/3214\/class-java"},"author":{"name":"Margaret Rouse","@id":"https:\/\/www.techopedia.com\/#\/schema\/person\/f5dd538e31ee352d105b8af36c4268a5"},"headline":"Class","datePublished":"2011-11-03T12:02:56+00:00","dateModified":"2021-08-24T20:22:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.techopedia.com\/definition\/3214\/class-java"},"wordCount":570,"commentCount":0,"publisher":{"@id":"https:\/\/www.techopedia.com\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.techopedia.com\/definition\/3214\/class-java#respond"]}],"articleSection":""},{"@type":"WebPage","@id":"https:\/\/www.techopedia.com\/definition\/3214\/class-java","url":"https:\/\/www.techopedia.com\/definition\/3214\/class-java","name":"What is a Class? - Definition from Techopedia","isPartOf":{"@id":"https:\/\/www.techopedia.com\/#website"},"datePublished":"2011-11-03T12:02:56+00:00","dateModified":"2021-08-24T20:22:44+00:00","description":"This definition explains the meaning of Class and why it matters.","breadcrumb":{"@id":"https:\/\/www.techopedia.com\/definition\/3214\/class-java#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.techopedia.com\/definition\/3214\/class-java"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.techopedia.com\/definition\/3214\/class-java#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.techopedia.com\/"},{"@type":"ListItem","position":2,"name":"DevOps","item":"https:\/\/www.techopedia.com\/topic\/324\/devops"},{"@type":"ListItem","position":3,"name":"Programming Languages","item":"https:\/\/www.techopedia.com\/topic\/89\/programming-languages"},{"@type":"ListItem","position":4,"name":"Term","item":"https:\/\/www.techopedia.com\/definition"},{"@type":"ListItem","position":5,"name":"Class"}]},{"@type":"WebSite","@id":"https:\/\/www.techopedia.com\/#website","url":"https:\/\/www.techopedia.com\/","name":"Techopedia","description":"","publisher":{"@id":"https:\/\/www.techopedia.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.techopedia.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.techopedia.com\/#organization","name":"Techopedia","url":"https:\/\/www.techopedia.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techopedia.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.techopedia.com\/wp-content\/uploads\/2025\/02\/techopedia-light-logo.svg","contentUrl":"https:\/\/www.techopedia.com\/wp-content\/uploads\/2025\/02\/techopedia-light-logo.svg","caption":"Techopedia"},"image":{"@id":"https:\/\/www.techopedia.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/techopedia\/","https:\/\/x.com\/techopedia","https:\/\/www.linkedin.com\/company\/techopedia\/","https:\/\/www.youtube.com\/c\/Techopedia"],"publishingPrinciples":"https:\/\/www.techopedia.com\/about\/editorial-policy","ownershipFundingInfo":"https:\/\/www.techopedia.com\/about"},{"@type":"Person","@id":"https:\/\/www.techopedia.com\/#\/schema\/person\/f5dd538e31ee352d105b8af36c4268a5","name":"Margaret Rouse","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techopedia.com\/#\/schema\/person\/image\/","url":"https:\/\/www.techopedia.com\/wp-content\/uploads\/2023\/02\/margaret-rouse-headshot.jpeg","contentUrl":"https:\/\/www.techopedia.com\/wp-content\/uploads\/2023\/02\/margaret-rouse-headshot.jpeg","caption":"Margaret Rouse"},"description":"Margaret is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other\u2019s highly specialized languages.","sameAs":["https:\/\/www.linkedin.com\/in\/margaretrouse\/","https:\/\/x.com\/https:\/\/twitter.com\/@techdefinitions"],"knowsAbout":["Technology Expert"],"url":"https:\/\/www.techopedia.com\/contributors\/margaret-rouse"}]}},"_links":{"self":[{"href":"https:\/\/www.techopedia.com\/wp-json\/wp\/v2\/definition\/3058","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.techopedia.com\/wp-json\/wp\/v2\/definition"}],"about":[{"href":"https:\/\/www.techopedia.com\/wp-json\/wp\/v2\/types\/definition"}],"author":[{"embeddable":true,"href":"https:\/\/www.techopedia.com\/wp-json\/wp\/v2\/users\/7813"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techopedia.com\/wp-json\/wp\/v2\/comments?post=3058"}],"version-history":[{"count":1,"href":"https:\/\/www.techopedia.com\/wp-json\/wp\/v2\/definition\/3058\/revisions"}],"predecessor-version":[{"id":316543,"href":"https:\/\/www.techopedia.com\/wp-json\/wp\/v2\/definition\/3058\/revisions\/316543"}],"wp:attachment":[{"href":"https:\/\/www.techopedia.com\/wp-json\/wp\/v2\/media?parent=3058"}],"wp:term":[{"taxonomy":"definitioncat","embeddable":true,"href":"https:\/\/www.techopedia.com\/wp-json\/wp\/v2\/definitioncat?post=3058"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}