Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Mastering object-oriented programming (OOP) concepts in Java empowers you to create robust and well-structured applications. Associations, a fundamental pillar of OOP, define relationships between objects.
This interactive quiz delves into the world of Java associations, testing your understanding of various association types and their characteristics. By attempting the quiz, you’ll gain valuable insights into how objects interact and collaborate within your Java programs. Let’s test your knowledge.
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.
What is the type of relation that composition associations have ?
Correct
Incorrect
Question 11 of 15
11. Question
class Employee {
String empname;
Employee( String empname )
{
return empname;
}
}
class Salary {
float salary;
Salary ( String salary )
{
return salary;
}
}
class Company {
public static void main ( String args [ ] )
{
Employee e1 = new Employee(“Kumar”);
Employee e2 = new Employee(“Thakur”);
Employee e3 = new Employee(“Singh”);
Salary s1 = new Salary(15000);
Salary s2 = new Salary(13000);
Salary s3 = new Salary(10000);
HashTable<Float , String > list = new HashTable();
list.add(e1,s1);
list.add(e2.s2);
list.add(e3,s3);
System.out.println(list);
}
}
What will be the output of the program ?
Correct
Incorrect
Question 12 of 15
12. Question
class Sample {
public void display()
{
System.out.println(“Sample class is needed”);
}
}
class Concept {
Private Sample sample;
Concept(Sample sample)
{
this.sample = sample:
}
public void display()
{
sample.display();
System.out.println(“Concept is explained”);
}
}
class Main {
public static void main ( String args [ ] )
{
Sample s = new Sample();
Concept c = new Concept();
c.display();
}
}
What is the output of the program ?
Correct
Incorrect
Question 13 of 15
13. Question
Which technique is highly employed while using associations ?
Correct
Incorrect
Question 14 of 15
14. Question
class Associations {
public void print(String a )
{
return a;
}
}
class Aggregation {
public void print(String b)
{
return b;
}
}
class Composition {
public void print( String c )
{
return c;
}
}
class Main {
public static void main ( String args [ ] )
{
Associations a1 = new Associations(“Connection between two class objects”);
Aggregations a2 = new Aggregations(“Is-A relationship association”);
Composition a3 = new Composition (“Has-A relationship association”);
a2.print();
}
}
What is the output of the program ?
Correct
Incorrect
Question 15 of 15
15. Question
class Vegetables {
public void veg ( String vegetable )
{
return vegetable;
}
}
class Fruits {
public void fru ( String fruit )
{
return fruit;
}
}
class Consumable {
public static void main ( String args [ ] )
{
Vegetables v1 = new Vegetables(“Tomato”);
Vegetable v2 = new Vegetables(“Beetroot”);
Vegetable v3 = new Vegetables(“Potato”):
Fruits f1 = new Fruits(“Apple”);
Fruits f2 = new Fruits(“Orange”);
List<String> list = new List();
list.add(v1);
list.add(v2);
list.add(v3);
list.add(f1);
list.add(f2);
if(list.size==5)
{
System.out.println(“Both Vegetables and fruits are added”);
} else {
System.out.println(“Only one is added”);
}
}
What is the output of the program ?
Correct
Incorrect
Summary:
So you’ve taken the Java Association Quiz and put your knowledge to the test! By tackling this quiz, you’ve refreshed your understanding of core association concepts like Has-A relationships, aggregation, and composition.
Remember, a strong grasp of these concepts is essential for building robust object-oriented systems in Java. Explore additional learning resources beyond the quiz to solidify your knowledge. Consider online tutorials, courses, or practice exercises to further your understanding of associations and their applications in Java programming.
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.