Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Are you ready to dive headfirst into the exciting world of Java classes and objects? This interactive quiz is like a treasure map, helping you uncover how well you understand the key building blocks of Java.
Whether you’re a coding champion or just setting off on your Java adventure, this quiz is your personal training ground. It’s a fun and dynamic way to test your knowledge, find your strengths, and discover areas where you can become an even better Java programmer.
So, buckle up, put your thinking cap on, and get ready to be challenged! This quiz will reveal your grasp of object-oriented programming fundamentals in Java, making you a more confident coder in no time! Let’s test your knowledge on Java Classes and Objects Quiz.
Time limit: 0
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
system.out.println( name + “ “ + “ , “ + number );
}
}
Correct
Incorrect
Question 3 of 15
3. Question
What is the error in the program?
class Demo {
}
demo ( String name) {
void display()
{
system.out.println(name);
}
}
public static void main ( String args [] )
{
Demo object = new Demo;
object.display();
}
Correct
Incorrect
Question 4 of 15
4. Question
What will be the output of the program?
public static void add(int a , int b , int sum)
{
sum = a + b ;
}
public static void main ( String args [] )
{
int a = 1;
int b = 2;
int sum ;
add(a,b);
system.out .println(“ Sum is “ + sum );
}
Correct
Incorrect
Question 5 of 15
5. Question
These are two separate files saved with .java extension. Which file has to be executed to display the output?
Class First {
String name = “DataFlair”;
Int branches = 3;
Void display ( ) {
system.out.println(“Company name is “ + name + “ and it has “ + branches + “ branches “);
}
Public static void main ( String args [] ) {
First object = new First;
object.display();
}
Correct
Incorrect
Question 6 of 15
6. Question
Which of the following is the syntax for abstract classes in Java?
Correct
Incorrect
Question 7 of 15
7. Question
Which of the following is a mutable class in Java?
Correct
Incorrect
Question 8 of 15
8. Question
Which of the following is true about Static classes in Java?
Correct
Incorrect
Question 9 of 15
9. Question
From the program given below select the type of class it exhibits?
Class Organisms {
String human;
Class Humans {
system.out.println(“We are Humans”);
}
}
Correct
Incorrect
Question 10 of 15
10. Question
This program exhibits sum and product calculation. All the methods are implemented and this can also be instantiated. What type of class is this?
class Main {
static int product(int a, int b)
{
return a * b;
}
static int sum(int a, int b)
{
return a + b;
}
public static void main(String args[])
{
int p = product(5, 10);
int s = sum(5, 10);
System.out.println(“Product: ” + p);
System.out.println(“Sum: ” + s);
}
}
Correct
Incorrect
Question 11 of 15
11. Question
Where the variable data should be declared in a non static class?
class Outer{
class Inner
{
void msg() {
System.out.println(“data is “+data);
}
}
publicstaticvoid main(String args[]){
Outer obj=new TestMemberOuter1();
Outer.Inner in=obj.new Inner();
in.msg();
}
}
Correct
Incorrect
Question 12 of 15
12. Question
Which of the following is not a rule for writing singleton classes?
Correct
Incorrect
Question 13 of 15
13. Question
The given program is an example program for inheritance. Object should be created for which class to invoke both the methods?
Class organisms {
String Human = “people” , animals = “ Lion “;
Void display () {
system.out.println( Human + animals );
}
}
Class animals extends organisms {
Void display2() {
system.out.println(“The king of jungle is “ + animals );
}
}
Class Main {
Public static void main ( String args [] )
{
}
}
Correct
Incorrect
Question 14 of 15
14. Question
What will be the output of the given program?
public class Sample
{
}
public class Main
{
public static void main(String[] args)
{
System.out.println(“DataFlair”);
}
}
Correct
Incorrect
Question 15 of 15
15. Question
What will be the output of the program?
class DataFlair
{
int branches;
}
class Main
{
public static void main( String args [ ] )
{
DataFlair b = new DataFlair();
b.branches = 30;
DataFlair b2 = b;
b = null;
System.out.println(” No. of branches =” + b.branches);
}
}
Correct
Incorrect
Summary:
Congratulations on conquering the Java Classes and Objects Quiz! Tackling these questions was a fantastic first step towards becoming a Java pro.
Remember, the road to mastering Java is paved with continuous learning. Don’t stop here! Dive into even more resources like online courses, tutorials, and practice problems. These will help you solidify your understanding of the fundamentals and build your coding muscles. Don’t forget the power of community!
Engaging with other Java developers online through forums and groups can be incredibly valuable. They can answer your questions, share their knowledge, and keep you up-to-date with the latest trends in the Java world.
So keep exploring, keep practising, and keep connecting with fellow programmers. This is just the beginning of your exciting Java development journey!
If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google
DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.