Posts

Showing posts from September, 2018

Gate Exam Solutions

Image
GATE | GATE-CS-2017 (Set 2) | Question 53 Consider the following C Program: #include<stdio.h> #include<string.h> int main() { char * c = "GATECSIT2017"; char *p = c; printf("%d", (int)strlen(c+2[p]-6[p]-1)); return 0; } The output of the program is _________. [Note: It was Numerical Answer Type Question.] Solution: The output of the program is 2. If you have any questions, ask in the comment box.
Q1. Write a program in JAVA to calculate the area of triangle, circle, square and rectangle. However, you need to ensure that the preceding set of functionalities must be achieved by implementing abstraction. Solution: // Java program to illustrate the // concept of Abstraction abstract class Shape { String color; // these are abstract methods abstract double area(); public abstract String toString(); // abstract class can have the constructor public Shape(String color) { System.out.println("Shape constructor called"); this.color = color; } // this is a concrete method public String getColor() { return color; } } class Circle extends Shape { double radius; public Circle(String color, double radius) { // calling Shape constructor super(color); System.out.println("Circle constructor called"); this.radius = radius; } @Override double area() { return Math.PI * Math.pow(radius, 2); } @Override public String ...