logo

Crowdly

CS102 - Object-Oriented Programming 1 F1 - S25

Looking for CS102 - Object-Oriented Programming 1 F1 - S25 test answers and solutions? Browse our comprehensive collection of verified answers for CS102 - Object-Oriented Programming 1 F1 - S25 at moodle.medtech.tn.

Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!

In Java, each child class can have only one parent.

 

View this question

What is the output of the following program?

  1. class  Parent{  
  2.    void PrintData() {  
  3.       System.out.println("method of parent class");  
  4.    }  
  5. }  
  6.   
  7. class Child extends Parent {  
  8.    void PrintData() {  
  9.       System.out.println("method of child class");  
  10.    }  
  11. }  
  12. class UpcastingExample{  
  13.    public static void main(String args[]) {  
  14.         
  15.       Parent obj1 = (Parent) new Child();  
  16.       Parent obj2 = (Parent) new Child();   
  17.       obj1.PrintData();  
  18.       obj2.PrintData();  
  19.    }  
  20. }  
0%
0%
0%
View this question

What is the purpose of upcasting in Java? 

View this question

What is the output of the following code snippet?

class Person{

String name;

Person(){

  System.out.println("In Person class");

  }

}

class Student extends Person{

Student(){

  System.out.println("In Student class");

  }

int id;

public static void main(String[] a){

Student ob=new Student(); //Line 1

ob.name="abc"; //Line 2

ob.id=123;}

}

 

View this question

What is the output of this program

class Person{

String name;

Person(){

name="John";

}

}

class Employee extends Person{

int age;

Employee(){

age=34;

}

}

class Customer extends Person{

int salary;

Customer(int salary){

this.salary=salary;

name="Maddy";

}

public void displayDetails(){

System.out.println(name+age+salary);

}

}

class Account {

public static void main(String[] args) {

Customer c=new Customer(20000);

c.displayDetails();

}

}

View this question

What is the output of the following program?

class SolarSystem {

}

class Earth extends SolarSystem {

}

class Mars extends SolarSystem {

}

public class Moon extends Earth {

public static void main(String args[])

{

SolarSystem s = new SolarSystem();

Earth e = new Earth();

Mars m = new Mars();

System.out.println(s instanceof SolarSystem);

System.out.println(e instanceof Earth);

System.out.println(m instanceof SolarSystem);

}

}

0%
0%
0%
View this question

What is the output of the following program?

  1. class Parent {   
  2.     String name;   
  3.     
  4.     void showMessage()   

  5.     {   
  6.         System.out.println("Parent method is called");   
  7.     }   
  8. }   
  9. class Child extends Parent {   

  10.     int age;   
  11.     
  12.     @Override  

  13.     void showMessage()   
  14.     {   
  15.         System.out.println("Child method is called");   
  16.     }   
  17. }   
  18.     
  19. public class Downcasting{  
  20.     
  21.     public static void main(String[] args)   
  22.     {   
  23.         Parent p = new Child();  
  24.         p.name = "Adrian";  
  25.       
  26.         Child c = (Child)p;   
  27.         c.age = 18;   
  28.         System.out.println(c.name);   
  29.         System.out.println(c.age);   
  30.         c.showMessage();   
  31.     }   
  32. }  
View this question

What is the output of the following program?

class Animal {

protected String name;

protected void display() {

System.out.println("I am an animal.");

}

}

class Dog extends Animal {

protected void display() {

System.out.println("I am a Dog");

}

public void getInfo() {

System.out.println("My name is " + name);

}

}

class Main {

public static void main(String[] args) {

// create an object of the subclass

Dog labrador = new Dog();

// access protected field and method

// using the object of subclass

labrador.name = "Rocky";

labrador.display();

labrador.getInfo();

}

}

0%
0%
View this question

In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?

View this question

What is the output of this program?

class A {

    int i;}

 

class B extends A {

        int j;

    void display() 

    {   super.i = j + 1;

        System.out.println(j + " " + i); }

}    

 

class inheritance {

    public static void main(String args[]) {

        B obj = new B();

       obj.i=1;

       obj.j=2;   

       obj.display(); }

}

View this question

Want instant access to all verified answers on moodle.medtech.tn?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!