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

Viewers also liked (13)

Operator overloading
Operator overloading Operator overloading
Operator overloading
Northeastern University
 
Classical programming interview questions
Classical programming interview questionsClassical programming interview questions
Classical programming interview questions
Gradeup
 
Interview questions(programming)
Interview questions(programming)Interview questions(programming)
Interview questions(programming)
sunilbhaisora1
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
Nishan Barot
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
Gradeup
 
Most Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerMost Asked Java Interview Question and Answer
Most Asked Java Interview Question and Answer
TOPS Technologies
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
Soumya Behera
 
Java codes
Java codesJava codes
Java codes
Hussain Sherwani
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
RACHIT_GUPTA
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
Mumbai Academisc
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloading
Haresh Jaiswal
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kumar
 
Java practical
Java practicalJava practical
Java practical
shweta-sharma99
 
Classical programming interview questions
Classical programming interview questionsClassical programming interview questions
Classical programming interview questions
Gradeup
 
Interview questions(programming)
Interview questions(programming)Interview questions(programming)
Interview questions(programming)
sunilbhaisora1
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
Nishan Barot
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
Gradeup
 
Most Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerMost Asked Java Interview Question and Answer
Most Asked Java Interview Question and Answer
TOPS Technologies
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
Soumya Behera
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
RACHIT_GUPTA
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloading
Haresh Jaiswal
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kumar
 

Similar to Java classes and objects interview questions (20)

Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
zynofustechnology
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
Vinay Kumar
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
Ahmad sohail Kakar
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
Sunil Kumar Gunasekaran
 
Corejavainterviewquestions.doc
Corejavainterviewquestions.docCorejavainterviewquestions.doc
Corejavainterviewquestions.doc
Joyce Thomas
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
venud11
 
Top 1000 Java Interview Questions_ Includes Spring, Hibernate, Microservices,...
Top 1000 Java Interview Questions_ Includes Spring, Hibernate, Microservices,...Top 1000 Java Interview Questions_ Includes Spring, Hibernate, Microservices,...
Top 1000 Java Interview Questions_ Includes Spring, Hibernate, Microservices,...
AJEET KUMAR
 
Top 1000 Java Interview Questions Includes Spring, Hibernate, Microservices, ...
Top 1000 Java Interview Questions Includes Spring, Hibernate, Microservices, ...Top 1000 Java Interview Questions Includes Spring, Hibernate, Microservices, ...
Top 1000 Java Interview Questions Includes Spring, Hibernate, Microservices, ...
Ankit Kumar
 
Java Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHatJava Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHat
Scholarhat
 
Oop java
Oop javaOop java
Oop java
Minal Maniar
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
Class and Object JAVA PROGRAMMING LANG .pdf
Class and Object JAVA PROGRAMMING LANG .pdfClass and Object JAVA PROGRAMMING LANG .pdf
Class and Object JAVA PROGRAMMING LANG .pdf
sameer2543ynr
 
Class and Object.pptx from nit patna ece department
Class and Object.pptx from nit patna ece departmentClass and Object.pptx from nit patna ece department
Class and Object.pptx from nit patna ece department
om2348023vats
 
Introduction to OOPs second year cse.pptx
Introduction to OOPs second year cse.pptxIntroduction to OOPs second year cse.pptx
Introduction to OOPs second year cse.pptx
solemanhldr
 
Core Java interview questions-ppt
Core Java interview questions-pptCore Java interview questions-ppt
Core Java interview questions-ppt
Mayank Kumar
 
Core java interview faq
Core java interview faqCore java interview faq
Core java interview faq
Kumaran K
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
VinishA23
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
Madhavendra Dutt
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
Shashwat Shriparv
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
zynofustechnology
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
Vinay Kumar
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
Sunil Kumar Gunasekaran
 
Corejavainterviewquestions.doc
Corejavainterviewquestions.docCorejavainterviewquestions.doc
Corejavainterviewquestions.doc
Joyce Thomas
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
venud11
 
Top 1000 Java Interview Questions_ Includes Spring, Hibernate, Microservices,...
Top 1000 Java Interview Questions_ Includes Spring, Hibernate, Microservices,...Top 1000 Java Interview Questions_ Includes Spring, Hibernate, Microservices,...
Top 1000 Java Interview Questions_ Includes Spring, Hibernate, Microservices,...
AJEET KUMAR
 
Top 1000 Java Interview Questions Includes Spring, Hibernate, Microservices, ...
Top 1000 Java Interview Questions Includes Spring, Hibernate, Microservices, ...Top 1000 Java Interview Questions Includes Spring, Hibernate, Microservices, ...
Top 1000 Java Interview Questions Includes Spring, Hibernate, Microservices, ...
Ankit Kumar
 
Java Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHatJava Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHat
Scholarhat
 
Class and Object JAVA PROGRAMMING LANG .pdf
Class and Object JAVA PROGRAMMING LANG .pdfClass and Object JAVA PROGRAMMING LANG .pdf
Class and Object JAVA PROGRAMMING LANG .pdf
sameer2543ynr
 
Class and Object.pptx from nit patna ece department
Class and Object.pptx from nit patna ece departmentClass and Object.pptx from nit patna ece department
Class and Object.pptx from nit patna ece department
om2348023vats
 
Introduction to OOPs second year cse.pptx
Introduction to OOPs second year cse.pptxIntroduction to OOPs second year cse.pptx
Introduction to OOPs second year cse.pptx
solemanhldr
 
Core Java interview questions-ppt
Core Java interview questions-pptCore Java interview questions-ppt
Core Java interview questions-ppt
Mayank Kumar
 
Core java interview faq
Core java interview faqCore java interview faq
Core java interview faq
Kumaran K
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
VinishA23
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
Madhavendra Dutt
 
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?