Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (55.6k points)
Can anyone explain about classes in Java?

1 Answer

0 votes
by (119k points)

Class is just like a blueprint or sketch of how the objects should look like. Classes names can be in mixed cases but should start with a capital letter and do not use acronyms like HTML, URL.

Example: Class MyFirstProgram

Classes can have three types of variables like local variables, instance variables, and class variables.

Local variables are initialized in the method or functions in a class.

Instance variables are those initialized outside methods or functions but inside a class.

Class variables are those initialized outside the method but in a class with the static keyword before the variable.  

public class Dog {

   String breed;

   int age;

   String color; 

   void barking() {

   }

   void sleeping() {

   }

}

If you are interested in Java, you can enroll this Java course by intellipaat. 

 You can watch this video on Java for a detailed explanation:

Related questions

0 votes
1 answer
asked Mar 6, 2021 in Java by Jake (7k points)
0 votes
0 answers
asked Jun 24, 2021 in Java by Harsh (1.5k points)
0 votes
1 answer
asked Feb 16, 2021 in Java by Jake (7k points)
0 votes
1 answer

Browse Categories

...