CoreJava - FAQs - Part 1
Core Java - FAQs - Part 1 Q: What is a static variable in Java? A: A static variable in Java is a variable that belongs to the class itself, rather than to any individual instance of the class. Static variables are shared among all instances of the class and can be accessed using the class name rather than an instance variable. Q: What is a static method in Java? A: A static method in Java is a method that belongs to the class itself, rather than to any individual instance of the class. Static methods can be called using the class name rather than an instance variable, and they cannot access non-static data members or methods. Q: What is the difference between a public and a private variable in Java? A: A public variable in Java can be accessed and modified by any code that has access to the object, while a private variable can only be accessed and modified by code within the same class. Q: What is encapsulation in Java? A: Encapsulation is the practice of...