- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are Java classes?
A class in Java is a user-defined datatype, a blueprint, a classification, that describes the behavior/state that the object of its type support.
Example
public class Dog { String breed; int age; String color; void barking() { } void hungry() { } void sleeping() { } }
A class can contain any of the following variable types.
Local variables − Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.
Instance variables − Instance variables are variables within a class but outside any method. These variables are initialized when the class is instantiated. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.
Class variables − Class variables are variables declared within a class, outside any method, with the static keyword.
- Related Articles
- What are final classes in Java?
- What are abstract classes in Java?
- What are inner classes in Java?
- What are wrapper classes in Java?
- What are I/O classes in Java?
- What are anonymous inner classes in Java?
- What are Java parent and child classes in Java?
- What are method local inner classes in Java?
- What are the differences between Java classes and Java objects?
- What are the different types of classes in Java?
- What are the different types of nested classes are defined in Java?
- What are the different Http/2 Client classes in Java 9?
- What are CSS pseudo-classes
- Primitive Wrapper Classes are Immutable in Java
- What are abstract classes in C#?
