Question

Hello, I need a output for the following code as well as screenshots from the eclipse...

Hello, I need a output for the following code as well as screenshots from the eclipse page showing the output. Thank you

public class COMP1050 {
    public static void main(String[] args) {
        System.out.printf("before");
        new CS();
        System.out.printf(".after");
    }
    
}

public class CS extends WIT {
    public CS() {
        System.out.printf(".cs");
    }
}

public class WIT {
    public WIT() {
        System.out.printf(".wit");
    }
}

Homework Answers

Answer #1

Explanation: So we have two classes WIT and CIS, we also have a main class COMP1050. WIT class have a constructor which prints ".wit" and CS class extends this WIT class and also have its seperate constructor which prints ".cs".

Now in the main method first we are printing "before" and after that creating an object of CS class, this will automatically calls the constructor and will print ".wit" and ".cs", after that we will print ".after".

So the final output will be before.wit.cs.after.

Have a look at the below code and the screenshot of output.

public class COMP1050 {
    public static void main(String[] args) {
        System.out.printf("before");
        new CS();
        System.out.printf(".after");
    }
    
}

public class CS extends WIT {
    public CS() {
        System.out.printf(".cs");
    }
}

public class WIT {
    public WIT() {
        System.out.printf(".wit");
    }
} 

// Output: before.wit.cs.after

Happy Learning!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
When I wrote this code in the Eclipse program, I did not see a output .....
When I wrote this code in the Eclipse program, I did not see a output .. Why? ___________________ public class YClass { private int a; private int b; public void one(){ } public void two ( int x , int y ) ; a=x; b=y; } public YClass() { a=0; b=0; } } class XClass extends YClass{ private int z; public void one() { } public XClass { z=0; } } YClass Object; XClass Object;
What is the output of the following Java program? class Food { Food() { System.out.println(flavor); }...
What is the output of the following Java program? class Food { Food() { System.out.println(flavor); } String flavor = "bland"; } class Pepper extends Food { String flavor = "spicy"; } public class Lunch { public static void main(String[] args) { Food lunch = new Pepper(); } } Select one: a. spicy b. the program does not compile c. bland spicy d. no output e. bland
What is the output of the following Java program? class Food { String flavor = "bland";...
What is the output of the following Java program? class Food { String flavor = "bland"; } class Pepper extends Food { String flavor = "spicy"; Pepper(String flavor) { this.flavor = flavor; } } public class Lunch { public static void main(String[] args) { Pepper pepper = new Pepper("sweet"); System.out.println(pepper.flavor); } } Select one: a. bland b. the program does not compile c. no output d. spicy e. sweet
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have this much public class Main { int WIDTH = 0; double HEIGHT = 0; public static void drawSmileyFaces() { System.out.println(" :-):-):-):-):-):-)"); } public static void main (String[] args) { for (int WIDTH = 0; WIDTH < 3; WIDTH++ ) { for(double HEIGHT = 0; HEIGHT < 2; HEIGHT++) { drawSmileyFaces(); } } } } I am pretty sure that alot of this is wrong...
Hello, I am trying to create a Java program that reads a .txt file and outputs...
Hello, I am trying to create a Java program that reads a .txt file and outputs how many times the word "and" is used. I attempted modifying a code I had previously used for counting the total number of tokens, but now it is saying there is an input mismatch. Please help! My code is below: import java.util.*; import java.io.*; public class Hamlet2 { public static void main(String[] args) throws FileNotFoundException { File file = new File("hamlet.txt"); Scanner fileRead =...
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1...
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1 = new String("hello"); String s2 = "hello"; String s3 = "hello";    System.out.println(s1 == s3); System.out.println(s1.equals(s3)); System.out.println(s2 == s3); } } When we run the program, the output is: false true true Explain why this is the output, using words and/or pictures.
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
Mention the concepts analyzed from the below given program and write the output. [0.5 M] class...
Mention the concepts analyzed from the below given program and write the output. [0.5 M] class Test { int a, b; Test(int i, int j) { a = i; b = j; } void meth(Test s) { s.a *= 2; s.b /= 2; } } class demo { public static void main(String args[]) { Test ob = new Test(15, 20); System.out.println("Before call: " + ob.a + " " + ob.b); ob.meth(ob); System.out.println("After call: " + ob.a + " " +...
This is Java programing.Modify this Java code,so that each franchise can assign and print their own...
This is Java programing.Modify this Java code,so that each franchise can assign and print their own burger price.The programing have at least three franchises. (Use abstract) class newBurger { public newBurger() { } public void salmonBurger(){    System.out.println("salmonBurger $5.99");    System.out.println("Kcal: 294"); } public void clamBurger(){    System.out.println("clamBurger $4.99");    System.out.println("Kcal: 200"); } public void oysterBurger(){    System.out.println("oysterBurger $3.50");    System.out.println("Kcal: 125"); } } class franchise1 extends newBurger { String name = "franchise #1"; public franchise1() { } } public...