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.
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 15 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
-
Question 1 of 15
1. Question
What will be the value of x printed?
- class MyExample {
int x = 10;
}
public static void main ( String args [] )
{
MyExample object = new MyExample;
object.x = 15;
system.out.println(x);
}
CorrectIncorrect -
Question 2 of 15
2. Question
What will be the output of the program?
class Sample {
string name;
int number;
}
public static void main ( String args [] ) {
Sample object = new Sample;
object.name(“DataFlair”);
object.number();
system.out.println( name + “ “ + “ , “ + number );
}
}
CorrectIncorrect -
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();
}
CorrectIncorrect -
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 );
}
CorrectIncorrect -
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();
}
CorrectIncorrect -
Question 6 of 15
6. Question
Which of the following is the syntax for abstract classes in Java?
CorrectIncorrect -
Question 7 of 15
7. Question
Which of the following is a mutable class in Java?
CorrectIncorrect -
Question 8 of 15
8. Question
Which of the following is true about Static classes in Java?
CorrectIncorrect -
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”);
}
}
CorrectIncorrect -
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);
}
}
CorrectIncorrect -
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);
}
}
public static void main(String args[]){
Outer obj=new TestMemberOuter1();
Outer.Inner in=obj.new Inner();
in.msg();
}
}
CorrectIncorrect -
Question 12 of 15
12. Question
Which of the following is not a rule for writing singleton classes?
CorrectIncorrect -
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 [] )
{
}
}
CorrectIncorrect -
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”);
}
}
CorrectIncorrect -
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);
}
}
CorrectIncorrect
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!
