SlideShare a Scribd company logo
Java Classes and Objects Interview Questions
What restrictions are placed on method overloading?

Two methods may not have the same name and argument list but different return types.

What is the difference between String and StringBuffer?

String objects are immutable whereas StringBuffer objects are not. StringBuffer unlike Strings
support growable and modifiable strings.

Can a private method of a superclass be declared within a subclass?

Sure. A private field or method or inner class belongs to its declared class and hides from its
subclasses.
There is no way for private stuff to have a runtime overloading or overriding (polymorphism)
features.

What is the default value of an object reference declared as an instance variable?

null unless we define it explicitly.

What is the difference between a constructor and a method?

Or

How can a subclass call a method or a constructor defined in a superclass?

A constructor is a member function of a class that is used to create objects of that class, invoked
using the new operator. It has the same name as the class and has no return type. They are only
called once, whereas member functions can be called many times. A method is an ordinary
member function of a class. It has its own name, a return type (which may be void), and is
invoked using the dot operator. Constructor will be automatically invoked when an object is
created whereas method has to be called explicitly.

super.method(); is used to call a super class method from a sub class. To call a constructor of the
super class, we use the super(); statement as the first line of the subclass’s constructor.

Can a top-level class be private or protected?

No. A top-level class cannot be private or protected. It can have either "public" or no modifier. If it
does not have a modifier it is supposed to have a default access. If a top level class is declared
as private/protected the compiler will complain that the "modifier private is not allowed here”.

Why Java does not support multiple inheritance?

Java does support multiple inheritance via interface implementation.

Where and how can you use a private constructor?

More Related Content

PDF
Tiếng anh chuyên ngành cntt
PDF
BÀI GIẢNG THIẾT KẾ, XÂY DỰNG MẠNG_10433312092019
PDF
Case ih farmall 55 a tractor service repair manual
DOCX
Basic java important interview questions and answers to secure a job
PPT
Operator overloading
PDF
Classical programming interview questions
DOCX
Interview questions(programming)
DOC
Final JAVA Practical of BCA SEM-5.
Tiếng anh chuyên ngành cntt
BÀI GIẢNG THIẾT KẾ, XÂY DỰNG MẠNG_10433312092019
Case ih farmall 55 a tractor service repair manual
Basic java important interview questions and answers to secure a job
Operator overloading
Classical programming interview questions
Interview questions(programming)
Final JAVA Practical of BCA SEM-5.

Viewers also liked (9)

PDF
20 most important java programming interview questions
PPT
Most Asked Java Interview Question and Answer
PDF
Advanced Java Practical File
DOCX
Java codes
DOCX
Java PRACTICAL file
PDF
Java programming-examples
PDF
06. operator overloading
PPTX
Operator overloading
DOCX
Java practical
20 most important java programming interview questions
Most Asked Java Interview Question and Answer
Advanced Java Practical File
Java codes
Java PRACTICAL file
Java programming-examples
06. operator overloading
Operator overloading
Java practical
Ad

Similar to Java classes and objects interview questions (20)

PPTX
Chapter 9 java
DOCX
Java Interview Questions For Freshers
DOCX
Java Core Parctical
PPTX
PPT Lecture-1.4.pptx
PPTX
C# interview
PPT
9781439035665 ppt ch10
DOC
116824015 java-j2 ee
PDF
Lecture 10
PDF
JAVA UNIT 2 BCA students' notes IPU university
PDF
Java - Inheritance Concepts
PPTX
OCA Java SE 8 Exam Chapter 5 Class Design
PDF
Java/J2EE interview Qestions
PPTX
Object Oriented Programming - Polymorphism and Interfaces
PDF
1669617800196.pdf
PPTX
Chapter 8 java
PPTX
Inheritance and Polymorphism
PPTX
Java interview questions 1
PDF
Java inheritance
Chapter 9 java
Java Interview Questions For Freshers
Java Core Parctical
PPT Lecture-1.4.pptx
C# interview
9781439035665 ppt ch10
116824015 java-j2 ee
Lecture 10
JAVA UNIT 2 BCA students' notes IPU university
Java - Inheritance Concepts
OCA Java SE 8 Exam Chapter 5 Class Design
Java/J2EE interview Qestions
Object Oriented Programming - Polymorphism and Interfaces
1669617800196.pdf
Chapter 8 java
Inheritance and Polymorphism
Java interview questions 1
Java inheritance
Ad

Java classes and objects interview questions

  • 1. Java Classes and Objects Interview Questions What restrictions are placed on method overloading? Two methods may not have the same name and argument list but different return types. What is the difference between String and StringBuffer? String objects are immutable whereas StringBuffer objects are not. StringBuffer unlike Strings support growable and modifiable strings. Can a private method of a superclass be declared within a subclass? Sure. A private field or method or inner class belongs to its declared class and hides from its subclasses. There is no way for private stuff to have a runtime overloading or overriding (polymorphism) features. What is the default value of an object reference declared as an instance variable? null unless we define it explicitly. What is the difference between a constructor and a method? Or How can a subclass call a method or a constructor defined in a superclass? A constructor is a member function of a class that is used to create objects of that class, invoked using the new operator. It has the same name as the class and has no return type. They are only called once, whereas member functions can be called many times. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator. Constructor will be automatically invoked when an object is created whereas method has to be called explicitly. super.method(); is used to call a super class method from a sub class. To call a constructor of the super class, we use the super(); statement as the first line of the subclass’s constructor. Can a top-level class be private or protected? No. A top-level class cannot be private or protected. It can have either "public" or no modifier. If it does not have a modifier it is supposed to have a default access. If a top level class is declared as private/protected the compiler will complain that the "modifier private is not allowed here”. Why Java does not support multiple inheritance? Java does support multiple inheritance via interface implementation. Where and how can you use a private constructor?