0% found this document useful (0 votes)
7 views13 pages

Java Classes, Objects, and Concepts Guide

The document is a comprehensive guide covering various fundamental concepts of Java, including classes, objects, constructors, inheritance, polymorphism, abstraction, interfaces, encapsulation, packages, access modifiers, and keywords like 'this', 'super', and 'static'. Each section contains questions and answers that explain the definitions, differences, and implementations of these concepts in Java programming. It serves as a valuable resource for understanding object-oriented programming principles in Java.

Uploaded by

manimishra2006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views13 pages

Java Classes, Objects, and Concepts Guide

The document is a comprehensive guide covering various fundamental concepts of Java, including classes, objects, constructors, inheritance, polymorphism, abstraction, interfaces, encapsulation, packages, access modifiers, and keywords like 'this', 'super', and 'static'. Each section contains questions and answers that explain the definitions, differences, and implementations of these concepts in Java programming. It serves as a valuable resource for understanding object-oriented programming principles in Java.

Uploaded by

manimishra2006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Classes, Methods & Objects

1.
What is a class in Java?

2.
What is an object in Java?

3.
How do you create an object in Java?

4.
What is the difference between a class and an object?

5.
What are instance variables and class variables?

6.
What is the purpose of the new keyword?

7.
Can a class have multiple objects?

8.
What is the difference between reference and object?

9.
What is the difference between instance method and static method?

10.
Can we define methods inside methods in Java?

11.
What is the purpose of this in a class method?

12.
Can a class be declared as both final and abstract?

13.
What happens if you do not define a constructor in a class?

Constructors
1.
What is a constructor?

2.
How is a constructor different from a method?

3.
What are the types of constructors in Java?

4.
What is a default constructor?

5.
What is a parameterized constructor?

6.
What is a copy constructor? Does Java support it?

7.
Can constructors be overloaded?

8.
Can a constructor be private?

9.
Can constructors be inherited?

10.
Can you call one constructor from another? How?

11.
What happens if you explicitly define a parameterized constructor but no default constructor?
12.
What is the order of constructor calls in inheritance?

Relationship Between Classes


1.
What are the different types of relationships between classes in Java?

2.
What is the difference between Association, Aggregation, and Composition?

3.
What is an example of each type of relationship?

4.
Why are relationships important in OOP?

5.
How do relationships affect coupling?

Association (HAS-A Relationship)


1.
What is an association in Java?

2.
What is a HAS-A relationship?

3.
How is association implemented in Java?

4.
What is the difference between association and aggregation?
5.
Can association be bidirectional?

6.
Give a real-world example of association.

7.
How do we represent association in UML?

Dependency (USES-A Relationship)


1.
What is a dependency in Java?

2.
What is the USES-A relationship?

3.
How is dependency implemented?

4.
How does dependency differ from association?

5.
What is dependency injection?

6.
What is tight coupling vs loose coupling?

7.
How do you reduce dependency between classes?

Inheritance (IS-A Relationship)


1.
What is inheritance?

2.
What is the IS-A relationship?

3.
What are the advantages of inheritance?

4.
What is the extends keyword used for?

5.
Can you inherit multiple classes in Java? Why not?

6.
What is hierarchical inheritance?

7.
What is multilevel inheritance?

8.
Can constructors be inherited?

9.
How do you call a superclass constructor?

10.
What is method overriding?

11.
What happens when you override a method?

12.
What are the rules for overriding a method?

13.
What is the difference between overriding and overloading?
14.
How is dynamic binding related to inheritance?

Polymorphism
1.
What is polymorphism in Java?

2.
What are the two types of polymorphism?

3.
What is compile-time polymorphism? Give examples.

4.
What is runtime polymorphism? Give examples.

5.
What is method overloading?

6.
What is method overriding?

7.
Can constructors be overloaded?

8.
Can constructors be overridden?

9.
What is the role of @Override annotation?

10.
Can you override a static method?

11.
Can you override a private method?
12.
What is the difference between early and late binding?

13.
How does JVM determine which method to call at runtime?

Abstraction
1.
What is abstraction in Java?

2.
Why is abstraction important?

3.
How is abstraction implemented in Java?

4.
What is the difference between abstraction and encapsulation?

5.
What is an abstract class?

6.
Can we create an object of an abstract class?

7.
Can an abstract class have constructors?

8.
Can an abstract class have non-abstract methods?

9.
Can an abstract class have static methods?

10.
Can an abstract class be final?

11.
What is the difference between interface and abstract class?

12.
When to use abstract class vs interface?

Interfaces
1.
What is an interface in Java?

2.
Why do we need interfaces?

3.
How do you define an interface?

4.
Can interfaces have constructors?

5.
Can interfaces have variables?

6.
What is the default modifier for interface methods and variables?

7.
What are default and static methods in interfaces?

8.
Can an interface extend another interface?

9.
Can an interface extend a class?
10.
Can a class implement multiple interfaces?

11.
What happens if two interfaces have same method signature?

12.
Can interfaces have private methods?

13.
What is functional interface?

14.
What is marker interface?

15.
Give examples of in-built Java marker interfaces.

Encapsulation
1.
What is encapsulation?

2.
How is encapsulation implemented in Java?

3.
What is data hiding?

4.
What is the difference between encapsulation and abstraction?

5.
Why are getters and setters used?

6.
What happens if fields are public and there are no getters/setters?

7.
What are the advantages of encapsulation?

8.
Can you break encapsulation in Java?

Packages
1.
What is a package in Java?

2.
What are advantages of using packages?

3.
How do you create a package?

4.
How do you access a class from another package?

5.
What is the difference between import and static import?

6.
Can we have two classes with same name in different packages?

7.
What is the default package?

8.
How do packages help avoid naming conflicts?
Access Modifiers
1.
What are access modifiers in Java?

2.
What are the four access levels in Java?

3.
Explain public, private, protected, and default.

4.
What is the default access modifier if none is specified?

5.
Can a class be private or protected?

6.
What is the difference between protected and default?

7.
How do access modifiers affect inheritance?

8.
Can private methods be inherited?

this Keyword
1.
What is this keyword in Java?

2.
What are the uses of this keyword?

3.
How does this differentiate instance variables from parameters?
4.
Can this be passed as an argument?

5.
Can you call another constructor using this()?

6.
Can this keyword be used in a static method?

7.
What is the difference between this() and super()?

super Keyword
1.
What is super keyword in Java?

2.
What are the uses of super keyword?

3.
How do you call a superclass constructor using super()?

4.
Can super() and this() be used together in a constructor?

5.
How is super used to access overridden methods?

6.
Can super be used in static methods?

7.
How does super differ from this?
static Keyword
1.
What does the static keyword mean in Java?

2.
What are static variables?

3.
What are static methods?

4.
Can static methods access instance variables?

5.
Can we override static methods?

6.
Can we use this or super in a static context?

7.
What is static block? When does it execute?

8.
Can we have multiple static blocks in a class?

9.
What is the order of execution of static and instance blocks?

10.
Can constructors be static?

You might also like